Home | History | Annotate | Download | only in frame
      1 // Copyright (c) 2011 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/chromeos/frame/dom_browser_view_layout.h"
      6 
      7 #include <algorithm>
      8 
      9 #include "chrome/browser/chromeos/status/status_area_view.h"
     10 #include "chrome/browser/chromeos/view_ids.h"
     11 #include "views/window/hit_test.h"
     12 
     13 namespace chromeos {
     14 
     15 // DOMBrowserViewLayout public: ------------------------------------------------
     16 
     17 DOMBrowserViewLayout::DOMBrowserViewLayout() : ::BrowserViewLayout() {}
     18 
     19 DOMBrowserViewLayout::~DOMBrowserViewLayout() {}
     20 
     21 // DOMBrowserViewLayout, ::DOMBrowserViewLayout overrides: ---------------------
     22 
     23 void DOMBrowserViewLayout::Installed(views::View* host) {
     24   status_area_ = NULL;
     25   ::BrowserViewLayout::Installed(host);
     26 }
     27 
     28 void DOMBrowserViewLayout::ViewAdded(views::View* host,
     29                                      views::View* view) {
     30   ::BrowserViewLayout::ViewAdded(host, view);
     31   switch (view->GetID()) {
     32     case VIEW_ID_STATUS_AREA:
     33       status_area_ = static_cast<chromeos::StatusAreaView*>(view);
     34       break;
     35   }
     36 }
     37 
     38 int DOMBrowserViewLayout::LayoutTabStrip() {
     39   status_area_->SetVisible(true);
     40   gfx::Size status_size = status_area_->GetPreferredSize();
     41   status_area_->SetBounds(vertical_layout_rect_.width() - status_size.width(),
     42                           0,
     43                           vertical_layout_rect_.width(),
     44                           status_size.height());
     45 
     46   return status_size.height();
     47 }
     48 
     49 int DOMBrowserViewLayout::LayoutToolbar(int top) {
     50   return top;
     51 }
     52 
     53 int DOMBrowserViewLayout::LayoutBookmarkAndInfoBars(int top) {
     54   return top;
     55 }
     56 
     57 bool DOMBrowserViewLayout::IsPositionInWindowCaption(const gfx::Point& point) {
     58   return false;
     59 }
     60 
     61 int DOMBrowserViewLayout::NonClientHitTest(const gfx::Point& point) {
     62   views::View* parent = browser_view_->parent();
     63   gfx::Point point_in_browser_view_coords(point);
     64   views::View::ConvertPointToView(
     65       parent, browser_view_, &point_in_browser_view_coords);
     66   gfx::Rect bv_bounds = browser_view_->bounds();
     67   if (bv_bounds.Contains(point))
     68     return HTCLIENT;
     69   // If the point is somewhere else, delegate to the default implementation.
     70   return browser_view_->views::ClientView::NonClientHitTest(point);
     71 }
     72 
     73 // DOMBrowserViewLayout private: -----------------------------------------------
     74 
     75 bool DOMBrowserViewLayout::IsPointInViewsInTitleArea(const gfx::Point& point)
     76     const {
     77   gfx::Point point_in_status_area_coords(point);
     78   views::View::ConvertPointToView(browser_view_, status_area_,
     79                                   &point_in_status_area_coords);
     80   return status_area_->HitTest(point_in_status_area_coords);
     81 }
     82 
     83 int DOMBrowserViewLayout::LayoutTitlebarComponents(const gfx::Rect& bounds) {
     84   status_area_->SetVisible(true);
     85   gfx::Size status_size = status_area_->GetPreferredSize();
     86   status_area_->SetBounds(bounds.right() - status_size.width(),
     87                           bounds.y(),
     88                           status_size.width(),
     89                           status_size.height());
     90   return status_size.height();
     91 }
     92 
     93 const DOMBrowserView* DOMBrowserViewLayout::GetDOMBrowserView() {
     94   return static_cast<DOMBrowserView*>(browser_view_);
     95 }
     96 
     97 }  // namespace chromeos
     98