Home | History | Annotate | Download | only in frame
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/frame/contents_layout_manager.h"
      6 
      7 #include "ui/views/view.h"
      8 
      9 ContentsLayoutManager::ContentsLayoutManager(
     10     views::View* devtools_view,
     11     views::View* contents_view)
     12     : devtools_view_(devtools_view),
     13       contents_view_(contents_view),
     14       host_(NULL),
     15       active_top_margin_(0) {
     16 }
     17 
     18 ContentsLayoutManager::~ContentsLayoutManager() {
     19 }
     20 
     21 void ContentsLayoutManager::SetContentsResizingStrategy(
     22     const DevToolsContentsResizingStrategy& strategy) {
     23   if (strategy_.Equals(strategy))
     24     return;
     25 
     26   strategy_.CopyFrom(strategy);
     27   if (host_)
     28     host_->InvalidateLayout();
     29 }
     30 
     31 void ContentsLayoutManager::SetActiveTopMargin(int margin) {
     32   if (active_top_margin_ == margin)
     33     return;
     34 
     35   active_top_margin_ = margin;
     36   if (host_)
     37     host_->InvalidateLayout();
     38 }
     39 
     40 void ContentsLayoutManager::Layout(views::View* contents_container) {
     41   DCHECK(host_ == contents_container);
     42 
     43   int top = active_top_margin_;
     44   int height = std::max(0, contents_container->height() - top);
     45   int width = contents_container->width();
     46 
     47   gfx::Size container_size(width, height);
     48   gfx::Rect old_devtools_bounds(devtools_view_->bounds());
     49   gfx::Rect old_contents_bounds(contents_view_->bounds());
     50   gfx::Rect new_devtools_bounds;
     51   gfx::Rect new_contents_bounds;
     52 
     53   old_devtools_bounds.Offset(0, -top);
     54   old_contents_bounds.Offset(0, -top);
     55   ApplyDevToolsContentsResizingStrategy(strategy_, container_size,
     56       old_devtools_bounds, old_contents_bounds,
     57       &new_devtools_bounds, &new_contents_bounds);
     58   new_devtools_bounds.Offset(0, top);
     59   new_contents_bounds.Offset(0, top);
     60 
     61   // DevTools cares about the specific position, so we have to compensate RTL
     62   // layout here.
     63   new_devtools_bounds.set_x(host_->GetMirroredXForRect(new_devtools_bounds));
     64   new_contents_bounds.set_x(host_->GetMirroredXForRect(new_contents_bounds));
     65 
     66   devtools_view_->SetBoundsRect(new_devtools_bounds);
     67   contents_view_->SetBoundsRect(new_contents_bounds);
     68 }
     69 
     70 gfx::Size ContentsLayoutManager::GetPreferredSize(
     71     const views::View* host) const {
     72   return gfx::Size();
     73 }
     74 
     75 void ContentsLayoutManager::Installed(views::View* host) {
     76   DCHECK(!host_);
     77   host_ = host;
     78 }
     79 
     80 void ContentsLayoutManager::Uninstalled(views::View* host) {
     81   DCHECK(host_ == host);
     82   host_ = NULL;
     83 }
     84