summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/frame
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/frame')
-rw-r--r--chrome/browser/views/frame/app_panel_browser_frame_view.cc505
-rw-r--r--chrome/browser/views/frame/app_panel_browser_frame_view.h123
-rw-r--r--chrome/browser/views/frame/browser_bubble_host.cc43
-rw-r--r--chrome/browser/views/frame/browser_bubble_host.h36
-rw-r--r--chrome/browser/views/frame/browser_frame.h73
-rw-r--r--chrome/browser/views/frame/browser_frame_gtk.cc154
-rw-r--r--chrome/browser/views/frame/browser_frame_gtk.h78
-rw-r--r--chrome/browser/views/frame/browser_frame_win.cc324
-rw-r--r--chrome/browser/views/frame/browser_frame_win.h94
-rw-r--r--chrome/browser/views/frame/browser_non_client_frame_view.h26
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc155
-rw-r--r--chrome/browser/views/frame/browser_root_view.h62
-rw-r--r--chrome/browser/views/frame/browser_view.cc2472
-rw-r--r--chrome/browser/views/frame/browser_view.h651
-rw-r--r--chrome/browser/views/frame/browser_view_layout.cc414
-rw-r--r--chrome/browser/views/frame/browser_view_layout.h103
-rw-r--r--chrome/browser/views/frame/contents_container.cc200
-rw-r--r--chrome/browser/views/frame/contents_container.h79
-rw-r--r--chrome/browser/views/frame/glass_browser_frame_view.cc511
-rw-r--r--chrome/browser/views/frame/glass_browser_frame_view.h96
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.cc1031
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.h141
-rw-r--r--chrome/browser/views/frame/popup_non_client_frame_view.cc58
-rw-r--r--chrome/browser/views/frame/popup_non_client_frame_view.h33
24 files changed, 43 insertions, 7419 deletions
diff --git a/chrome/browser/views/frame/app_panel_browser_frame_view.cc b/chrome/browser/views/frame/app_panel_browser_frame_view.cc
deleted file mode 100644
index d7efbe9..0000000
--- a/chrome/browser/views/frame/app_panel_browser_frame_view.cc
+++ /dev/null
@@ -1,505 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/app_panel_browser_frame_view.h"
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/compiler_specific.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "gfx/canvas.h"
-#include "gfx/font.h"
-#include "gfx/path.h"
-#include "grit/app_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-#include "views/controls/button/image_button.h"
-#include "views/window/window.h"
-#include "views/window/window_resources.h"
-
-#if defined(OS_LINUX)
-#include "views/window/hit_test.h"
-#endif
-
-namespace {
-// The frame border is only visible in restored mode and is hardcoded to 1 px on
-// each side regardless of the system window border size.
-const int kFrameBorderThickness = 1;
-// In the window corners, the resize areas don't actually expand bigger, but the
-// 16 px at the end of each edge triggers diagonal resizing.
-const int kResizeAreaCornerSize = 16;
-// The titlebar never shrinks too short to show the caption button plus some
-// padding below it.
-const int kCaptionButtonHeightWithPadding = 27;
-// The titlebar has a 2 px 3D edge along the bottom, and we reserve 2 px (1 for
-// border, 1 for padding) along the top.
-const int kTitlebarTopAndBottomEdgeThickness = 2;
-// The icon is inset 6 px from the left frame border.
-const int kIconLeftSpacing = 6;
-// The icon never shrinks below 16 px on a side.
-const int kIconMinimumSize = 16;
-// There is a 4 px gap between the icon and the title text.
-const int kIconTitleSpacing = 4;
-// There is a 5 px gap between the title text and the close button.
-const int kTitleCloseButtonSpacing = 5;
-// There is a 4 px gap between the close button and the frame border.
-const int kCloseButtonFrameBorderSpacing = 4;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, public:
-
-AppPanelBrowserFrameView::AppPanelBrowserFrameView(BrowserFrame* frame,
- BrowserView* browser_view)
- : BrowserNonClientFrameView(),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- close_button_(new views::ImageButton(this))),
- window_icon_(NULL),
- frame_(frame),
- browser_view_(browser_view) {
- DCHECK(browser_view->ShouldShowWindowIcon());
- DCHECK(browser_view->ShouldShowWindowTitle());
-
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- close_button_->SetImage(views::CustomButton::BS_NORMAL,
- rb.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::CustomButton::BS_HOT,
- rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::CustomButton::BS_PUSHED,
- rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
- close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
- AddChildView(close_button_);
-
- window_icon_ = new TabIconView(this);
- window_icon_->set_is_light(true);
- AddChildView(window_icon_);
- window_icon_->Update();
-}
-
-AppPanelBrowserFrameView::~AppPanelBrowserFrameView() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, BrowserNonClientFrameView implementation:
-
-gfx::Rect AppPanelBrowserFrameView::GetBoundsForTabStrip(
- BaseTabStrip* tabstrip) const {
- // App panels never show a tab strip.
- NOTREACHED();
- return gfx::Rect();
-}
-
-int AppPanelBrowserFrameView::GetHorizontalTabStripVerticalOffset(
- bool restored) const {
- // App panels are not themed and don't need this.
- return 0;
-}
-
-void AppPanelBrowserFrameView::UpdateThrobber(bool running) {
- window_icon_->Update();
-}
-
-gfx::Size AppPanelBrowserFrameView::GetMinimumSize() {
- gfx::Size min_size(browser_view_->GetMinimumSize());
- int border_thickness = NonClientBorderThickness();
- min_size.Enlarge(2 * border_thickness,
- NonClientTopBorderHeight() + border_thickness);
-
- min_size.set_width(std::max(min_size.width(),
- (2 * FrameBorderThickness()) + kIconLeftSpacing + IconSize() +
- kTitleCloseButtonSpacing + kCloseButtonFrameBorderSpacing));
- return min_size;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, views::NonClientFrameView implementation:
-
-gfx::Rect AppPanelBrowserFrameView::GetBoundsForClientView() const {
- return client_view_bounds_;
-}
-
-bool AppPanelBrowserFrameView::AlwaysUseCustomFrame() const {
- return true;
-}
-
-bool AppPanelBrowserFrameView::AlwaysUseNativeFrame() const {
- return frame_->AlwaysUseNativeFrame();
-}
-
-gfx::Rect AppPanelBrowserFrameView::GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const {
- int top_height = NonClientTopBorderHeight();
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
- std::max(0, client_bounds.y() - top_height),
- client_bounds.width() + (2 * border_thickness),
- client_bounds.height() + top_height + border_thickness);
-}
-
-int AppPanelBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
- if (!bounds().Contains(point))
- return HTNOWHERE;
-
- int frame_component =
- frame_->GetWindow()->GetClientView()->NonClientHitTest(point);
-
- // See if we're in the sysmenu region. (We check the ClientView first to be
- // consistent with OpaqueBrowserFrameView; it's not really necessary here.)
- gfx::Rect sysmenu_rect(IconBounds());
- // In maximized mode we extend the rect to the screen corner to take advantage
- // of Fitts' Law.
- if (frame_->GetWindow()->IsMaximized())
- sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom());
- sysmenu_rect.set_x(MirroredLeftPointForRect(sysmenu_rect));
- if (sysmenu_rect.Contains(point))
- return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
-
- if (frame_component != HTNOWHERE)
- return frame_component;
-
- // Then see if the point is within any of the window controls.
- if (close_button_->IsVisible() &&
- close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point))
- return HTCLOSE;
-
- int window_component = GetHTComponentForFrame(point,
- NonClientBorderThickness(), NonClientBorderThickness(),
- kResizeAreaCornerSize, kResizeAreaCornerSize,
- frame_->GetWindow()->GetDelegate()->CanResize());
- // Fall back to the caption if no other component matches.
- return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
-}
-
-void AppPanelBrowserFrameView::GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask) {
- DCHECK(window_mask);
-
- if (frame_->GetWindow()->IsMaximized())
- return;
-
- // Redefine the window visible region for the new size.
- window_mask->moveTo(0, 3);
- window_mask->lineTo(1, 2);
- window_mask->lineTo(1, 1);
- window_mask->lineTo(2, 1);
- window_mask->lineTo(3, 0);
-
- window_mask->lineTo(SkIntToScalar(size.width() - 3), 0);
- window_mask->lineTo(SkIntToScalar(size.width() - 2), 1);
- window_mask->lineTo(SkIntToScalar(size.width() - 1), 1);
- window_mask->lineTo(SkIntToScalar(size.width() - 1), 2);
- window_mask->lineTo(SkIntToScalar(size.width()), 3);
-
- window_mask->lineTo(SkIntToScalar(size.width()),
- SkIntToScalar(size.height()));
- window_mask->lineTo(0, SkIntToScalar(size.height()));
- window_mask->close();
-}
-
-void AppPanelBrowserFrameView::EnableClose(bool enable) {
- close_button_->SetEnabled(enable);
-}
-
-void AppPanelBrowserFrameView::ResetWindowControls() {
- // The close button isn't affected by this constraint.
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, views::View overrides:
-
-void AppPanelBrowserFrameView::Paint(gfx::Canvas* canvas) {
- views::Window* window = frame_->GetWindow();
- if (window->IsMaximized())
- PaintMaximizedFrameBorder(canvas);
- else
- PaintRestoredFrameBorder(canvas);
- PaintTitleBar(canvas);
- if (!window->IsMaximized())
- PaintRestoredClientEdge(canvas);
-}
-
-void AppPanelBrowserFrameView::Layout() {
- LayoutWindowControls();
- LayoutTitleBar();
- client_view_bounds_ = CalculateClientAreaBounds(width(), height());
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, views::ButtonListener implementation:
-
-void AppPanelBrowserFrameView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- if (sender == close_button_)
- frame_->GetWindow()->Close();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, TabIconView::TabContentsProvider implementation:
-
-bool AppPanelBrowserFrameView::ShouldTabIconViewAnimate() const {
- // This function is queried during the creation of the window as the
- // TabIconView we host is initialized, so we need to NULL check the selected
- // TabContents because in this condition there is not yet a selected tab.
- TabContents* current_tab = browser_view_->GetSelectedTabContents();
- return current_tab ? current_tab->is_loading() : false;
-}
-
-SkBitmap AppPanelBrowserFrameView::GetFavIconForTabIconView() {
- return frame_->GetWindow()->GetDelegate()->GetWindowIcon();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// AppPanelBrowserFrameView, private:
-
-int AppPanelBrowserFrameView::FrameBorderThickness() const {
- return frame_->GetWindow()->IsMaximized() ? 0 : kFrameBorderThickness;
-}
-
-int AppPanelBrowserFrameView::NonClientBorderThickness() const {
- return FrameBorderThickness() +
- (frame_->GetWindow()->IsMaximized() ? 0 : kClientEdgeThickness);
-}
-
-int AppPanelBrowserFrameView::NonClientTopBorderHeight() const {
- return std::max(FrameBorderThickness() + IconSize(),
- FrameBorderThickness() + kCaptionButtonHeightWithPadding) +
- TitlebarBottomThickness();
-}
-
-int AppPanelBrowserFrameView::TitlebarBottomThickness() const {
- return kTitlebarTopAndBottomEdgeThickness +
- (frame_->GetWindow()->IsMaximized() ? 0 : kClientEdgeThickness);
-}
-
-int AppPanelBrowserFrameView::IconSize() const {
-#if defined(OS_WIN)
- // This metric scales up if either the titlebar height or the titlebar font
- // size are increased.
- return GetSystemMetrics(SM_CYSMICON);
-#else
- return std::max(BrowserFrame::GetTitleFont().height(), kIconMinimumSize);
-#endif
-}
-
-gfx::Rect AppPanelBrowserFrameView::IconBounds() const {
- int size = IconSize();
- int frame_thickness = FrameBorderThickness();
- // Our frame border has a different "3D look" than Windows'. Theirs has a
- // more complex gradient on the top that they push their icon/title below;
- // then the maximized window cuts this off and the icon/title are centered
- // in the remaining space. Because the apparent shape of our border is
- // simpler, using the same positioning makes things look slightly uncentered
- // with restored windows, so when the window is restored, instead of
- // calculating the remaining space from below the frame border, we calculate
- // from below the top border-plus-padding.
- int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ?
- frame_thickness : kTitlebarTopAndBottomEdgeThickness;
- // When the icon is shorter than the minimum space we reserve for the caption
- // button, we vertically center it. We want to bias rounding to put extra
- // space above the icon, since the 3D edge (+ client edge, for restored
- // windows) below looks (to the eye) more like additional space than does the
- // border + padding (or nothing at all, for maximized windows) above; hence
- // the +1.
- int y = unavailable_px_at_top + (NonClientTopBorderHeight() -
- unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2;
- return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size);
-}
-
-void AppPanelBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
- SkBitmap* top_left_corner = rb.GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER);
- SkBitmap* top_right_corner =
- rb.GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER);
- SkBitmap* top_edge = rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER);
- SkBitmap* right_edge = rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE);
- SkBitmap* left_edge = rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE);
- SkBitmap* bottom_left_corner =
- rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER);
- SkBitmap* bottom_right_corner =
- rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER);
- SkBitmap* bottom_edge = rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER);
-
- // Window frame mode and color.
- SkBitmap* theme_frame;
- SkColor frame_color;
- if (ShouldPaintAsActive()) {
- theme_frame = rb.GetBitmapNamed(IDR_FRAME_APP_PANEL);
- frame_color = ResourceBundle::frame_color_app_panel;
- } else {
- theme_frame = rb.GetBitmapNamed(IDR_FRAME_APP_PANEL); // TODO
- frame_color = ResourceBundle::frame_color_app_panel_inactive;
- }
-
- // Fill with the frame color first so we have a constant background for
- // areas not covered by the theme image.
- canvas->FillRectInt(frame_color, 0, 0, width(), theme_frame->height());
- // Now fill down the sides.
- canvas->FillRectInt(frame_color, 0, theme_frame->height(), left_edge->width(),
- height() - theme_frame->height());
- canvas->FillRectInt(frame_color, width() - right_edge->width(),
- theme_frame->height(), right_edge->width(),
- height() - theme_frame->height());
- // Now fill the bottom area.
- canvas->FillRectInt(frame_color, left_edge->width(),
- height() - bottom_edge->height(),
- width() - left_edge->width() - right_edge->width(),
- bottom_edge->height());
-
- // Draw the theme frame.
- canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height());
-
- // Top.
- canvas->DrawBitmapInt(*top_left_corner, 0, 0);
- canvas->TileImageInt(*top_edge, top_left_corner->width(), 0,
- width() - top_right_corner->width(), top_edge->height());
- canvas->DrawBitmapInt(*top_right_corner,
- width() - top_right_corner->width(), 0);
-
- // Right.
- canvas->TileImageInt(*right_edge, width() - right_edge->width(),
- top_right_corner->height(), right_edge->width(),
- height() - top_right_corner->height() - bottom_right_corner->height());
-
- // Bottom.
- canvas->DrawBitmapInt(*bottom_right_corner,
- width() - bottom_right_corner->width(),
- height() - bottom_right_corner->height());
- canvas->TileImageInt(*bottom_edge, bottom_left_corner->width(),
- height() - bottom_edge->height(),
- width() - bottom_left_corner->width() - bottom_right_corner->width(),
- bottom_edge->height());
- canvas->DrawBitmapInt(*bottom_left_corner, 0,
- height() - bottom_left_corner->height());
-
- // Left.
- canvas->TileImageInt(*left_edge, 0, top_left_corner->height(),
- left_edge->width(),
- height() - top_left_corner->height() - bottom_left_corner->height());
-}
-
-void AppPanelBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
- SkBitmap* frame_image = rb.GetBitmapNamed(IDR_FRAME_APP_PANEL);
- canvas->TileImageInt(*frame_image, 0, FrameBorderThickness(), width(),
- frame_image->height());
-
- // The bottom of the titlebar actually comes from the top of the Client Edge
- // graphic, with the actual client edge clipped off the bottom.
- SkBitmap* titlebar_bottom = rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
- int edge_height = titlebar_bottom->height() - kClientEdgeThickness;
- canvas->TileImageInt(*titlebar_bottom, 0,
- frame_->GetWindow()->GetClientView()->y() - edge_height,
- width(), edge_height);
-}
-
-void AppPanelBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) {
- // The window icon is painted by the TabIconView.
- views::WindowDelegate* d = frame_->GetWindow()->GetDelegate();
- canvas->DrawStringInt(d->GetWindowTitle(), BrowserFrame::GetTitleFont(),
- SK_ColorBLACK, MirroredLeftPointForRect(title_bounds_), title_bounds_.y(),
- title_bounds_.width(), title_bounds_.height());
-}
-
-void AppPanelBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
- gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
- int client_area_top = client_area_bounds.y();
-
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- SkBitmap* top_left = rb.GetBitmapNamed(IDR_APP_TOP_LEFT);
- SkBitmap* top = rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
- SkBitmap* top_right = rb.GetBitmapNamed(IDR_APP_TOP_RIGHT);
- SkBitmap* right = rb.GetBitmapNamed(IDR_CONTENT_RIGHT_SIDE);
- SkBitmap* bottom_right =
- rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER);
- SkBitmap* bottom = rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_CENTER);
- SkBitmap* bottom_left =
- rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
- SkBitmap* left = rb.GetBitmapNamed(IDR_CONTENT_LEFT_SIDE);
-
- // Top.
- int top_edge_y = client_area_top - top->height();
- canvas->DrawBitmapInt(*top_left, client_area_bounds.x() - top_left->width(),
- top_edge_y);
- canvas->TileImageInt(*top, client_area_bounds.x(), top_edge_y,
- client_area_bounds.width(), top->height());
- canvas->DrawBitmapInt(*top_right, client_area_bounds.right(), top_edge_y);
-
- // Right.
- int client_area_bottom =
- std::max(client_area_top, client_area_bounds.bottom());
- int client_area_height = client_area_bottom - client_area_top;
- canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
- right->width(), client_area_height);
-
- // Bottom.
- canvas->DrawBitmapInt(*bottom_right, client_area_bounds.right(),
- client_area_bottom);
- canvas->TileImageInt(*bottom, client_area_bounds.x(), client_area_bottom,
- client_area_bounds.width(), bottom_right->height());
- canvas->DrawBitmapInt(*bottom_left,
- client_area_bounds.x() - bottom_left->width(), client_area_bottom);
-
- // Left.
- canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
- client_area_top, left->width(), client_area_height);
-
- // Draw the toolbar color to fill in the edges.
- canvas->DrawRectInt(ResourceBundle::toolbar_color,
- client_area_bounds.x() - kClientEdgeThickness,
- client_area_top - kClientEdgeThickness,
- client_area_bounds.width() + kClientEdgeThickness,
- client_area_bottom - client_area_top + kClientEdgeThickness);
-}
-
-void AppPanelBrowserFrameView::LayoutWindowControls() {
- close_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
- views::ImageButton::ALIGN_BOTTOM);
- bool is_maximized = frame_->GetWindow()->IsMaximized();
- // There should always be the same number of non-border pixels visible to the
- // side of the close button. In maximized mode we extend the button to the
- // screen corner to obey Fitts' Law.
- int right_extra_width = is_maximized ? kCloseButtonFrameBorderSpacing : 0;
- gfx::Size close_button_size = close_button_->GetPreferredSize();
- int close_button_y =
- (NonClientTopBorderHeight() - close_button_size.height()) / 2;
- int top_extra_height = is_maximized ? close_button_y : 0;
- close_button_->SetBounds(width() - FrameBorderThickness() -
- kCloseButtonFrameBorderSpacing - close_button_size.width(),
- close_button_y - top_extra_height,
- close_button_size.width() + right_extra_width,
- close_button_size.height() + top_extra_height);
-}
-
-void AppPanelBrowserFrameView::LayoutTitleBar() {
- // Size the icon first; the window title is based on the icon position.
- gfx::Rect icon_bounds(IconBounds());
- window_icon_->SetBounds(icon_bounds);
-
- // Size the title.
- int title_x = icon_bounds.right() + kIconTitleSpacing;
- int title_height = BrowserFrame::GetTitleFont().GetHeight();
- // We bias the title position so that when the difference between the icon
- // and title heights is odd, the extra pixel of the title is above the
- // vertical midline rather than below. This compensates for how the icon is
- // already biased downwards (see IconBounds()) and helps prevent descenders
- // on the title from overlapping the 3D edge at the bottom of the titlebar.
- title_bounds_.SetRect(title_x,
- icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2),
- std::max(0, close_button_->x() - kTitleCloseButtonSpacing - title_x),
- title_height);
-}
-
-gfx::Rect AppPanelBrowserFrameView::CalculateClientAreaBounds(int width,
- int height) const {
- int top_height = NonClientTopBorderHeight();
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(border_thickness, top_height,
- std::max(0, width - (2 * border_thickness)),
- std::max(0, height - top_height - border_thickness));
-}
diff --git a/chrome/browser/views/frame/app_panel_browser_frame_view.h b/chrome/browser/views/frame/app_panel_browser_frame_view.h
index eae6d9b..cc93319 100644
--- a/chrome/browser/views/frame/app_panel_browser_frame_view.h
+++ b/chrome/browser/views/frame/app_panel_browser_frame_view.h
@@ -6,125 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_APP_PANEL_BROWSER_FRAME_VIEW_H_
#pragma once
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/frame/browser_non_client_frame_view.h"
-#include "chrome/browser/views/tab_icon_view.h"
-#include "views/controls/button/button.h"
-#include "views/window/non_client_view.h"
-
-class BaseTabStrip;
-class BrowserView;
-class TabContents;
-namespace gfx {
-class Font;
-}
-namespace views {
-class ImageButton;
-class ImageView;
-}
-// The frame view which is used for Application Panels.
-// TODO(rafaelw): Refactor. This shares much duplicated code with
-// OpaqueBrowserFrameView.
-class AppPanelBrowserFrameView : public BrowserNonClientFrameView,
- public views::ButtonListener,
- public TabIconView::TabIconViewModel {
- public:
- // Constructs a non-client view for an BrowserFrame.
- AppPanelBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
- virtual ~AppPanelBrowserFrameView();
-
- // Overridden from BrowserNonClientFrameView:
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
- virtual gfx::Size GetMinimumSize();
-
- protected:
- // Overridden from views::NonClientFrameView:
- virtual gfx::Rect GetBoundsForClientView() const;
- virtual bool AlwaysUseCustomFrame() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
- virtual void EnableClose(bool enable);
- virtual void ResetWindowControls();
-
- // Overridden from views::View:
- virtual void Paint(gfx::Canvas* canvas);
- virtual void Layout();
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from TabIconView::TabIconViewModel:
- virtual bool ShouldTabIconViewAnimate() const;
- virtual SkBitmap GetFavIconForTabIconView();
-
- private:
- // Returns the thickness of the border that makes up the window frame edges.
- // This does not include any client edge.
- int FrameBorderThickness() const;
-
- // Returns the thickness of the entire nonclient left, right, and bottom
- // borders, including both the window frame and any client edge.
- int NonClientBorderThickness() const;
-
- // Returns the height of the entire nonclient top border, including the window
- // frame, any title area, and any connected client edge.
- int NonClientTopBorderHeight() const;
-
- // Returns the thickness of the nonclient portion of the 3D edge along the
- // bottom of the titlebar.
- int TitlebarBottomThickness() const;
-
- // Returns the size of the titlebar icon.
- int IconSize() const;
-
- // Returns the bounds of the titlebar icon.
- gfx::Rect IconBounds() const;
-
- // Paint various sub-components of this view. The *FrameBorder() function
- // also paints the background of the titlebar area, since the top frame border
- // and titlebar background are a contiguous component.
- void PaintRestoredFrameBorder(gfx::Canvas* canvas);
- void PaintMaximizedFrameBorder(gfx::Canvas* canvas);
- void PaintTitleBar(gfx::Canvas* canvas);
- void PaintRestoredClientEdge(gfx::Canvas* canvas);
-
- // Layout various sub-components of this view.
- void LayoutWindowControls();
- void LayoutTitleBar();
-
- // Returns the bounds of the client area for the specified view size.
- gfx::Rect CalculateClientAreaBounds(int width, int height) const;
-
- // The layout rect of the title, if visible.
- gfx::Rect title_bounds_;
-
- // Window controls.
- views::ImageButton* close_button_;
-
- // The Window icon.
- TabIconView* window_icon_;
-
- // The frame that hosts this view.
- BrowserFrame* frame_;
-
- // The BrowserView hosted within this View.
- BrowserView* browser_view_;
-
- // The bounds of the ClientView.
- gfx::Rect client_view_bounds_;
-
- // The accessible name of this view.
- std::wstring accessible_name_;
-
- static void InitAppWindowResources();
- static gfx::Font* title_font_;
-
- DISALLOW_COPY_AND_ASSIGN(AppPanelBrowserFrameView);
-};
+#include "chrome/browser/ui/views/frame/app_panel_browser_frame_view.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_APP_PANEL_BROWSER_FRAME_VIEW_H_
+
diff --git a/chrome/browser/views/frame/browser_bubble_host.cc b/chrome/browser/views/frame/browser_bubble_host.cc
deleted file mode 100644
index 60809bf..0000000
--- a/chrome/browser/views/frame/browser_bubble_host.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_bubble_host.h"
-
-#include "base/logging.h"
-#include "chrome/browser/views/browser_bubble.h"
-
-void BrowserBubbleHost::WindowMoved() {
- // Do safe iteration in case the bubble winds up closing as a result of this
- // message.
- for (BubbleSet::iterator i = browser_bubbles_.begin();
- i != browser_bubbles_.end();) {
- BubbleSet::iterator bubble = i++;
- (*bubble)->BrowserWindowMoved();
- }
-}
-
-void BrowserBubbleHost::AttachBrowserBubble(BrowserBubble* bubble) {
- DCHECK(browser_bubbles_.find(bubble) == browser_bubbles_.end()) <<
- "Attempt to register the same BrowserBubble multiple times.";
- browser_bubbles_.insert(bubble);
-}
-
-void BrowserBubbleHost::DetachBrowserBubble(BrowserBubble* bubble) {
- BubbleSet::iterator it = browser_bubbles_.find(bubble);
- DCHECK(it != browser_bubbles_.end()) <<
- "Attempt to detach an unrecognized BrowserBubble.";
- if (it != browser_bubbles_.end())
- browser_bubbles_.erase(it);
-}
-
-void BrowserBubbleHost::Close() {
- // BrowserWindowClosing will usually cause the bubble to remove itself from
- // the set, so we need to iterate in a way that's safe against deletion.
- for (BubbleSet::iterator i = browser_bubbles_.begin();
- i != browser_bubbles_.end();) {
- BubbleSet::iterator bubble = i++;
- (*bubble)->BrowserWindowClosing();
- }
-}
-
diff --git a/chrome/browser/views/frame/browser_bubble_host.h b/chrome/browser/views/frame/browser_bubble_host.h
index 99b8058..f903d99 100644
--- a/chrome/browser/views/frame/browser_bubble_host.h
+++ b/chrome/browser/views/frame/browser_bubble_host.h
@@ -6,38 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_BUBBLE_HOST_H_
#pragma once
-#include <set>
-
-#include "base/basictypes.h"
-
-class BrowserBubble;
-
-// A class providing a hosting environment for BrowserBubble instances.
-// Allows for notification to attached BrowserBubbles of browser move, and
-// close events.
-class BrowserBubbleHost {
- public:
- BrowserBubbleHost() {}
-
- // Invoked when the window containing the attached browser-bubbles is moved.
- // Calls BrowserBubble::BrowserWindowMoved on all attached bubbles.
- void WindowMoved();
-
- // To be called when the frame containing the BrowserBubbleHost is closing.
- // Calls BrowserBubble::BrowserWindowClosing on all attached bubbles.
- void Close();
-
- // Registers/Unregisters |bubble| to receive notifications when the host moves
- // or is closed.
- void AttachBrowserBubble(BrowserBubble* bubble);
- void DetachBrowserBubble(BrowserBubble* bubble);
-
- private:
- // The set of bubbles associated with this host.
- typedef std::set<BrowserBubble*> BubbleSet;
- BubbleSet browser_bubbles_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserBubbleHost);
-};
+#include "chrome/browser/ui/views/frame/browser_bubble_host.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_BUBBLE_HOST_H_
+
diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h
index 0e3b9b2..eaf9fe6 100644
--- a/chrome/browser/views/frame/browser_frame.h
+++ b/chrome/browser/views/frame/browser_frame.h
@@ -6,75 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_H_
#pragma once
-#include "build/build_config.h"
-#include "views/window/non_client_view.h"
-
-class BaseTabStrip;
-class BrowserView;
-class Profile;
-class ThemeProvider;
-
-namespace gfx {
-class Font;
-class Rect;
-} // namespace gfx
-
-namespace views {
-class Window;
-
-#if defined(OS_WIN)
-class WindowWin;
-#endif
-} // namespace views
-
-// This is a virtual interface that allows system specific browser frames.
-class BrowserFrame {
- public:
- virtual ~BrowserFrame() {}
-
- // Creates the appropriate BrowserFrame for this platform. The returned
- // object is owned by the caller.
- static BrowserFrame* Create(BrowserView* browser_view, Profile* profile);
-
- static const gfx::Font& GetTitleFont();
-
- // Returns the Window associated with this frame. Guraranteed non-NULL after
- // construction.
- virtual views::Window* GetWindow() = 0;
-
- // Determine the distance of the left edge of the minimize button from the
- // left edge of the window. Used in our Non-Client View's Layout.
- virtual int GetMinimizeButtonOffset() const = 0;
-
- // Retrieves the bounds, in non-client view coordinates for the specified
- // TabStrip.
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const = 0;
-
- // Returns the y coordinate within the window at which the horizontal TabStrip
- // begins (or would begin). If |restored| is true, this is calculated as if
- // we were in restored mode regardless of the current mode.
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const = 0;
-
- // Tells the frame to update the throbber.
- virtual void UpdateThrobber(bool running) = 0;
-
- // Tells the frame to continue a drag detached tab operation.
- virtual void ContinueDraggingDetachedTab() = 0;
-
- // Returns the theme provider for this frame.
- virtual ThemeProvider* GetThemeProviderForFrame() const = 0;
-
- // Returns true if the window should use the native frame view. This is true
- // if there are no themes applied on Vista, or if there are themes applied and
- // this browser window is an app or popup.
- virtual bool AlwaysUseNativeFrame() const = 0;
-
- // Returns the NonClientFrameView of this frame.
- virtual views::View* GetFrameView() const = 0;
-
- // Notifies the frame that the tab strip display mode changed so it can update
- // its frame treatment if necessary.
- virtual void TabStripDisplayModeChanged() = 0;
-};
+#include "chrome/browser/ui/views/frame/browser_frame.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_H_
+
diff --git a/chrome/browser/views/frame/browser_frame_gtk.cc b/chrome/browser/views/frame/browser_frame_gtk.cc
deleted file mode 100644
index 83a6acb..0000000
--- a/chrome/browser/views/frame/browser_frame_gtk.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_frame_gtk.h"
-
-#include "base/logging.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/status_bubble.h"
-#include "chrome/browser/themes/browser_theme_provider.h"
-#include "chrome/browser/views/frame/app_panel_browser_frame_view.h"
-#include "chrome/browser/views/frame/browser_root_view.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/frame/opaque_browser_frame_view.h"
-#include "chrome/browser/views/frame/popup_non_client_frame_view.h"
-#include "gfx/font.h"
-#include "views/widget/root_view.h"
-#include "views/window/hit_test.h"
-
-#if !defined(OS_CHROMEOS)
-// static (Factory method.)
-BrowserFrame* BrowserFrame::Create(BrowserView* browser_view,
- Profile* profile) {
- BrowserFrameGtk* frame = new BrowserFrameGtk(browser_view, profile);
- frame->Init();
- return frame;
-}
-#endif
-
-// static
-const gfx::Font& BrowserFrame::GetTitleFont() {
- static gfx::Font *title_font = new gfx::Font();
- return *title_font;
-}
-
-BrowserFrameGtk::BrowserFrameGtk(BrowserView* browser_view, Profile* profile)
- : WindowGtk(browser_view),
- browser_view_(browser_view),
- browser_frame_view_(NULL),
- root_view_(NULL),
- profile_(profile) {
- browser_view_->set_frame(this);
-}
-
-BrowserFrameGtk::~BrowserFrameGtk() {
-}
-
-void BrowserFrameGtk::Init() {
- if (browser_frame_view_ == NULL) {
- if (browser_view_->browser()->type() & Browser::TYPE_POPUP)
- browser_frame_view_ = new PopupNonClientFrameView();
- else
- browser_frame_view_ = new OpaqueBrowserFrameView(this, browser_view_);
- }
- GetNonClientView()->SetFrameView(browser_frame_view_);
- WindowGtk::Init(NULL, gfx::Rect());
- // Don't focus anything on creation, selecting a tab will set the focus.
-}
-
-views::Window* BrowserFrameGtk::GetWindow() {
- return this;
-}
-
-int BrowserFrameGtk::GetMinimizeButtonOffset() const {
- NOTIMPLEMENTED();
- return 0;
-}
-
-gfx::Rect BrowserFrameGtk::GetBoundsForTabStrip(BaseTabStrip* tabstrip) const {
- return browser_frame_view_->GetBoundsForTabStrip(tabstrip);
-}
-
-int BrowserFrameGtk::GetHorizontalTabStripVerticalOffset(bool restored) const {
- return browser_frame_view_->GetHorizontalTabStripVerticalOffset(restored);
-}
-
-void BrowserFrameGtk::UpdateThrobber(bool running) {
- browser_frame_view_->UpdateThrobber(running);
-}
-
-void BrowserFrameGtk::ContinueDraggingDetachedTab() {
- NOTIMPLEMENTED();
-}
-
-ThemeProvider* BrowserFrameGtk::GetThemeProviderForFrame() const {
- // This is implemented for a different interface than GetThemeProvider is,
- // but they mean the same things.
- return GetThemeProvider();
-}
-
-bool BrowserFrameGtk::AlwaysUseNativeFrame() const {
- return false;
-}
-
-views::View* BrowserFrameGtk::GetFrameView() const {
- return browser_frame_view_;
-}
-
-void BrowserFrameGtk::TabStripDisplayModeChanged() {
- if (GetRootView()->GetChildViewCount() > 0) {
- // Make sure the child of the root view gets Layout again.
- GetRootView()->GetChildViewAt(0)->InvalidateLayout();
- }
- GetRootView()->Layout();
-}
-
-ThemeProvider* BrowserFrameGtk::GetThemeProvider() const {
- return profile_->GetThemeProvider();
-}
-
-ThemeProvider* BrowserFrameGtk::GetDefaultThemeProvider() const {
- return profile_->GetThemeProvider();
-}
-
-views::RootView* BrowserFrameGtk::CreateRootView() {
- root_view_ = new BrowserRootView(browser_view_, this);
- return root_view_;
-}
-
-void BrowserFrameGtk::IsActiveChanged() {
- GetRootView()->SchedulePaint();
- browser_view_->ActivationChanged(IsActive());
- views::WidgetGtk::IsActiveChanged();
-}
-
-void BrowserFrameGtk::SetInitialFocus() {
- browser_view_->RestoreFocus();
-}
-
-bool BrowserFrameGtk::GetAccelerator(int cmd_id,
- menus::Accelerator* accelerator) {
- return browser_view_->GetAccelerator(cmd_id, accelerator);
-}
-
-gboolean BrowserFrameGtk::OnWindowStateEvent(GtkWidget* widget,
- GdkEventWindowState* event) {
- bool was_full_screen = IsFullscreen();
- gboolean result = views::WindowGtk::OnWindowStateEvent(widget, event);
- if ((!IsVisible() || IsMinimized()) && browser_view_->GetStatusBubble()) {
- // The window is effectively hidden. We have to hide the status bubble as
- // unlike windows gtk has no notion of child windows that are hidden along
- // with the parent.
- browser_view_->GetStatusBubble()->Hide();
- }
- if (was_full_screen != IsFullscreen())
- browser_view_->FullScreenStateChanged();
- return result;
-}
-
-gboolean BrowserFrameGtk::OnConfigureEvent(GtkWidget* widget,
- GdkEventConfigure* event) {
- browser_view_->WindowMoved();
- return views::WindowGtk::OnConfigureEvent(widget, event);
-}
diff --git a/chrome/browser/views/frame/browser_frame_gtk.h b/chrome/browser/views/frame/browser_frame_gtk.h
index 742eea5..1b8977c 100644
--- a/chrome/browser/views/frame/browser_frame_gtk.h
+++ b/chrome/browser/views/frame/browser_frame_gtk.h
@@ -6,80 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_GTK_H_
#pragma once
-#include "base/basictypes.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "views/window/window_gtk.h"
-
-class BrowserNonClientFrameView;
-class BrowserRootView;
-
-class BrowserFrameGtk : public BrowserFrame,
- public views::WindowGtk {
- public:
- // Normally you will create this class by calling BrowserFrame::Create.
- // Init must be called before using this class, which Create will do for you.
- BrowserFrameGtk(BrowserView* browser_view, Profile* profile);
- virtual ~BrowserFrameGtk();
-
- // Creates a frame view and initializes the window. This
- // initialization function must be called after construction, it is
- // separate to avoid recursive calling of the frame from its
- // constructor.
- virtual void Init();
-
- // Overridden from BrowserFrame:
- virtual views::Window* GetWindow();
- virtual int GetMinimizeButtonOffset() const;
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
- virtual void ContinueDraggingDetachedTab();
- virtual ThemeProvider* GetThemeProviderForFrame() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual views::View* GetFrameView() const;
- virtual void TabStripDisplayModeChanged();
-
- // Overridden from views::Widget:
- virtual ThemeProvider* GetThemeProvider() const;
- virtual ThemeProvider* GetDefaultThemeProvider() const;
- virtual void IsActiveChanged();
- virtual void SetInitialFocus();
-
- protected:
- void set_browser_frame_view(BrowserNonClientFrameView* browser_frame_view) {
- browser_frame_view_ = browser_frame_view;
- }
-
- // Overridden from views::WidgetGtk:
- virtual views::RootView* CreateRootView();
- virtual bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator);
-
- // Overriden from views::WindowGtk:
- virtual gboolean OnWindowStateEvent(GtkWidget* widget,
- GdkEventWindowState* event);
- virtual gboolean OnConfigureEvent(GtkWidget* widget,
- GdkEventConfigure* event);
-
- protected:
- BrowserView* browser_view() const {
- return browser_view_;
- }
-
- private:
- // The BrowserView is our ClientView. This is a pointer to it.
- BrowserView* browser_view_;
-
- // A pointer to our NonClientFrameView as a BrowserNonClientFrameView.
- BrowserNonClientFrameView* browser_frame_view_;
-
- // An unowning reference to the root view associated with the window. We save
- // a copy as a BrowserRootView to avoid evil casting later, when we need to
- // call functions that only exist on BrowserRootView (versus RootView).
- BrowserRootView* root_view_;
-
- Profile* profile_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserFrameGtk);
-};
+#include "chrome/browser/ui/views/frame/browser_frame_gtk.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_GTK_H_
+
diff --git a/chrome/browser/views/frame/browser_frame_win.cc b/chrome/browser/views/frame/browser_frame_win.cc
deleted file mode 100644
index bd5ddca..0000000
--- a/chrome/browser/views/frame/browser_frame_win.cc
+++ /dev/null
@@ -1,324 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_frame_win.h"
-
-#include <dwmapi.h>
-#include <shellapi.h>
-
-#include <set>
-
-#include "app/win_util.h"
-#include "base/win_util.h"
-#include "chrome/browser/accessibility/browser_accessibility_state.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/browser_list.h"
-#include "chrome/browser/themes/browser_theme_provider.h"
-#include "chrome/browser/views/frame/app_panel_browser_frame_view.h"
-#include "chrome/browser/views/frame/browser_non_client_frame_view.h"
-#include "chrome/browser/views/frame/browser_root_view.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/frame/glass_browser_frame_view.h"
-#include "chrome/browser/views/frame/opaque_browser_frame_view.h"
-#include "grit/theme_resources.h"
-#include "views/screen.h"
-#include "views/window/window_delegate.h"
-
-// static
-static const int kClientEdgeThickness = 3;
-static const int kTabDragWindowAlpha = 200;
-// We need to offset the DWMFrame into the toolbar so that the blackness
-// doesn't show up on our rounded corners.
-static const int kDWMFrameTopOffset = 3;
-
-// static (Factory method.)
-BrowserFrame* BrowserFrame::Create(BrowserView* browser_view,
- Profile* profile) {
- BrowserFrameWin* frame = new BrowserFrameWin(browser_view, profile);
- frame->Init();
- return frame;
-}
-
-// static
-const gfx::Font& BrowserFrame::GetTitleFont() {
- static gfx::Font* title_font = new gfx::Font(win_util::GetWindowTitleFont());
- return *title_font;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserFrame, public:
-
-BrowserFrameWin::BrowserFrameWin(BrowserView* browser_view, Profile* profile)
- : WindowWin(browser_view),
- browser_view_(browser_view),
- root_view_(NULL),
- frame_initialized_(false),
- profile_(profile) {
- browser_view_->set_frame(this);
- GetNonClientView()->SetFrameView(CreateFrameViewForWindow());
- // Don't focus anything on creation, selecting a tab will set the focus.
- set_focus_on_creation(false);
-}
-
-void BrowserFrameWin::Init() {
- WindowWin::Init(NULL, gfx::Rect());
-}
-
-BrowserFrameWin::~BrowserFrameWin() {
-}
-
-views::Window* BrowserFrameWin::GetWindow() {
- return this;
-}
-
-int BrowserFrameWin::GetMinimizeButtonOffset() const {
- TITLEBARINFOEX titlebar_info;
- titlebar_info.cbSize = sizeof(TITLEBARINFOEX);
- SendMessage(GetNativeView(), WM_GETTITLEBARINFOEX, 0, (WPARAM)&titlebar_info);
-
- CPoint minimize_button_corner(titlebar_info.rgrect[2].left,
- titlebar_info.rgrect[2].top);
- MapWindowPoints(HWND_DESKTOP, GetNativeView(), &minimize_button_corner, 1);
-
- return minimize_button_corner.x;
-}
-
-gfx::Rect BrowserFrameWin::GetBoundsForTabStrip(BaseTabStrip* tabstrip) const {
- return browser_frame_view_->GetBoundsForTabStrip(tabstrip);
-}
-
-int BrowserFrameWin::GetHorizontalTabStripVerticalOffset(bool restored) const {
- return browser_frame_view_->GetHorizontalTabStripVerticalOffset(restored);
-}
-
-void BrowserFrameWin::UpdateThrobber(bool running) {
- browser_frame_view_->UpdateThrobber(running);
-}
-
-void BrowserFrameWin::ContinueDraggingDetachedTab() {
- // Send the message directly, so that the window is positioned appropriately.
- SendMessage(GetNativeWindow(), WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(0, 0));
-}
-
-ThemeProvider* BrowserFrameWin::GetThemeProviderForFrame() const {
- // This is implemented for a different interface than GetThemeProvider is,
- // but they mean the same things.
- return GetThemeProvider();
-}
-
-bool BrowserFrameWin::AlwaysUseNativeFrame() const {
- // App panel windows draw their own frame.
- if (browser_view_->IsBrowserTypePanel())
- return false;
-
- if (browser_view_->browser()->type() == Browser::TYPE_EXTENSION_APP)
- return false;
-
- // We don't theme popup or app windows, so regardless of whether or not a
- // theme is active for normal browser windows, we don't want to use the custom
- // frame for popups/apps.
- if (!browser_view_->IsBrowserTypeNormal() && win_util::ShouldUseVistaFrame())
- return true;
-
- // Otherwise, we use the native frame when we're told we should by the theme
- // provider (e.g. no custom theme is active).
- return GetThemeProvider()->ShouldUseNativeFrame();
-}
-
-views::View* BrowserFrameWin::GetFrameView() const {
- return browser_frame_view_;
-}
-
-void BrowserFrameWin::TabStripDisplayModeChanged() {
- if (GetRootView()->GetChildViewCount() > 0) {
- // Make sure the child of the root view gets Layout again.
- GetRootView()->GetChildViewAt(0)->InvalidateLayout();
- }
- GetRootView()->Layout();
-
- UpdateDWMFrame();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserFrame, views::WindowWin overrides:
-
-gfx::Insets BrowserFrameWin::GetClientAreaInsets() const {
- // Use the default client insets for an opaque frame or a glass popup/app
- // frame.
- if (!GetNonClientView()->UseNativeFrame() ||
- !browser_view_->IsBrowserTypeNormal()) {
- return WindowWin::GetClientAreaInsets();
- }
-
- int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
- // In fullscreen mode, we have no frame. In restored mode, we draw our own
- // client edge over part of the default frame.
- if (IsFullscreen())
- border_thickness = 0;
- else if (!IsMaximized())
- border_thickness -= kClientEdgeThickness;
- return gfx::Insets(0, border_thickness, border_thickness, border_thickness);
-}
-
-bool BrowserFrameWin::GetAccelerator(int cmd_id,
- menus::Accelerator* accelerator) {
- return browser_view_->GetAccelerator(cmd_id, accelerator);
-}
-
-void BrowserFrameWin::OnEndSession(BOOL ending, UINT logoff) {
- BrowserList::WindowsSessionEnding();
-}
-
-void BrowserFrameWin::OnEnterSizeMove() {
- browser_view_->WindowMoveOrResizeStarted();
-}
-
-void BrowserFrameWin::OnExitSizeMove() {
- WidgetWin::OnExitSizeMove();
-}
-
-void BrowserFrameWin::OnInitMenuPopup(HMENU menu, UINT position,
- BOOL is_system_menu) {
- browser_view_->PrepareToRunSystemMenu(menu);
-}
-
-LRESULT BrowserFrameWin::OnMouseActivate(HWND window, UINT hittest_code,
- UINT message) {
- return browser_view_->ActivateAppModalDialog() ? MA_NOACTIVATEANDEAT
- : MA_ACTIVATE;
-}
-
-void BrowserFrameWin::OnMove(const CPoint& point) {
- browser_view_->WindowMoved();
-}
-
-void BrowserFrameWin::OnMoving(UINT param, LPRECT new_bounds) {
- browser_view_->WindowMoved();
-}
-
-LRESULT BrowserFrameWin::OnNCActivate(BOOL active) {
- if (browser_view_->ActivateAppModalDialog())
- return TRUE;
-
- browser_view_->ActivationChanged(!!active);
- return WindowWin::OnNCActivate(active);
-}
-
-LRESULT BrowserFrameWin::OnNCHitTest(const CPoint& pt) {
- // Only do DWM hit-testing when we are using the native frame.
- if (GetNonClientView()->UseNativeFrame()) {
- LRESULT result;
- if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
- MAKELPARAM(pt.x, pt.y), &result)) {
- return result;
- }
- }
- return WindowWin::OnNCHitTest(pt);
-}
-
-void BrowserFrameWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
- WindowWin::OnWindowPosChanged(window_pos);
- UpdateDWMFrame();
-
- // Windows lies to us about the position of the minimize button before a
- // window is visible. We use this position to place the OTR avatar in RTL
- // mode, so when the window is shown, we need to re-layout and schedule a
- // paint for the non-client frame view so that the icon top has the correct
- // position when the window becomes visible. This fixes bugs where the icon
- // appears to overlay the minimize button.
- // Note that we will call Layout every time SetWindowPos is called with
- // SWP_SHOWWINDOW, however callers typically are careful about not specifying
- // this flag unless necessary to avoid flicker.
- if (window_pos->flags & SWP_SHOWWINDOW) {
- GetNonClientView()->Layout();
- GetNonClientView()->SchedulePaint();
- }
-}
-
-ThemeProvider* BrowserFrameWin::GetThemeProvider() const {
- return profile_->GetThemeProvider();
-}
-
-ThemeProvider* BrowserFrameWin::GetDefaultThemeProvider() const {
- return profile_->GetThemeProvider();
-}
-
-void BrowserFrameWin::OnScreenReaderDetected() {
- Singleton<BrowserAccessibilityState>()->OnScreenReaderDetected();
- WindowWin::OnScreenReaderDetected();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserFrame, views::CustomFrameWindow overrides:
-
-int BrowserFrameWin::GetShowState() const {
- return browser_view_->GetShowState();
-}
-
-void BrowserFrameWin::Activate() {
- // When running under remote desktop, if the remote desktop client is not
- // active on the users desktop, then none of the windows contained in the
- // remote desktop will be activated. However, WindowWin::Activate will still
- // bring this browser window to the foreground. We explicitly set ourselves
- // as the last active browser window to ensure that we get treated as such by
- // the rest of Chrome.
- BrowserList::SetLastActive(browser_view_->browser());
-
- WindowWin::Activate();
-}
-
-views::NonClientFrameView* BrowserFrameWin::CreateFrameViewForWindow() {
- if (AlwaysUseNativeFrame())
- browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_);
- else if (browser_view_->IsBrowserTypePanel())
- browser_frame_view_ = new AppPanelBrowserFrameView(this, browser_view_);
- else
- browser_frame_view_ = new OpaqueBrowserFrameView(this, browser_view_);
- return browser_frame_view_;
-}
-
-void BrowserFrameWin::UpdateFrameAfterFrameChange() {
- // We need to update the glass region on or off before the base class adjusts
- // the window region.
- UpdateDWMFrame();
- WindowWin::UpdateFrameAfterFrameChange();
-}
-
-views::RootView* BrowserFrameWin::CreateRootView() {
- root_view_ = new BrowserRootView(browser_view_, this);
- return root_view_;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserFrame, private:
-
-void BrowserFrameWin::UpdateDWMFrame() {
- // Nothing to do yet, or we're not showing a DWM frame.
- if (!GetClientView() || !AlwaysUseNativeFrame())
- return;
-
- MARGINS margins = { 0 };
- if (browser_view_->IsBrowserTypeNormal()) {
- // In fullscreen mode, we don't extend glass into the client area at all,
- // because the GDI-drawn text in the web content composited over it will
- // become semi-transparent over any glass area.
- if (!IsMaximized() && !IsFullscreen()) {
- margins.cxLeftWidth = kClientEdgeThickness + 1;
- margins.cxRightWidth = kClientEdgeThickness + 1;
- margins.cyBottomHeight = kClientEdgeThickness + 1;
- margins.cyTopHeight = kClientEdgeThickness + 1;
- }
- // In maximized mode, we only have a titlebar strip of glass, no side/bottom
- // borders.
- if (!browser_view_->IsFullscreen()) {
- gfx::Rect tabstrip_bounds(
- GetBoundsForTabStrip(browser_view_->tabstrip()));
- margins.cyTopHeight = (browser_view_->UseVerticalTabs() ?
- tabstrip_bounds.y() : tabstrip_bounds.bottom()) + kDWMFrameTopOffset;
- }
- } else {
- // For popup and app windows we want to use the default margins.
- }
- DwmExtendFrameIntoClientArea(GetNativeView(), &margins);
-}
diff --git a/chrome/browser/views/frame/browser_frame_win.h b/chrome/browser/views/frame/browser_frame_win.h
index 1dbc4dd..b755e21 100644
--- a/chrome/browser/views/frame/browser_frame_win.h
+++ b/chrome/browser/views/frame/browser_frame_win.h
@@ -6,96 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_WIN_H_
#pragma once
-#include "base/basictypes.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "views/window/window_win.h"
-
-class AeroGlassNonClientView;
-class BrowserNonClientFrameView;
-class BrowserRootView;
-class BrowserView;
-class NonClientFrameView;
-class Profile;
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserFrameWin
-//
-// BrowserFrame is a WindowWin subclass that provides the window frame for the
-// Chrome browser window.
-//
-class BrowserFrameWin : public BrowserFrame, public views::WindowWin {
- public:
- // Normally you will create this class by calling BrowserFrame::Create.
- // Init must be called before using this class, which Create will do for you.
- BrowserFrameWin(BrowserView* browser_view, Profile* profile);
- virtual ~BrowserFrameWin();
-
- // This initialization function must be called after construction, it is
- // separate to avoid recursive calling of the frame from its constructor.
- void Init();
-
- BrowserView* browser_view() const { return browser_view_; }
-
- // BrowserFrame implementation.
- virtual views::Window* GetWindow();
- virtual int GetMinimizeButtonOffset() const;
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
- virtual void ContinueDraggingDetachedTab();
- virtual ThemeProvider* GetThemeProviderForFrame() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual views::View* GetFrameView() const;
- virtual void TabStripDisplayModeChanged();
-
- protected:
- // Overridden from views::WindowWin:
- virtual gfx::Insets GetClientAreaInsets() const;
- virtual bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator);
- virtual void OnEndSession(BOOL ending, UINT logoff);
- virtual void OnEnterSizeMove();
- virtual void OnExitSizeMove();
- virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
- virtual LRESULT OnMouseActivate(HWND window,
- UINT hittest_code,
- UINT message);
- virtual void OnMove(const CPoint& point);
- virtual void OnMoving(UINT param, LPRECT new_bounds);
- virtual LRESULT OnNCActivate(BOOL active);
- virtual LRESULT OnNCHitTest(const CPoint& pt);
- virtual void OnWindowPosChanged(WINDOWPOS* window_pos);
- virtual ThemeProvider* GetThemeProvider() const;
- virtual ThemeProvider* GetDefaultThemeProvider() const;
- virtual void OnScreenReaderDetected();
-
- // Overridden from views::Window:
- virtual int GetShowState() const;
- virtual void Activate();
- virtual bool IsAppWindow() const { return true; }
- virtual views::NonClientFrameView* CreateFrameViewForWindow();
- virtual void UpdateFrameAfterFrameChange();
- virtual views::RootView* CreateRootView();
-
- private:
- // Updates the DWM with the frame bounds.
- void UpdateDWMFrame();
-
- // The BrowserView is our ClientView. This is a pointer to it.
- BrowserView* browser_view_;
-
- // A pointer to our NonClientFrameView as a BrowserNonClientFrameView.
- BrowserNonClientFrameView* browser_frame_view_;
-
- // An unowning reference to the root view associated with the window. We save
- // a copy as a BrowserRootView to avoid evil casting later, when we need to
- // call functions that only exist on BrowserRootView (versus RootView).
- BrowserRootView* root_view_;
-
- bool frame_initialized_;
-
- Profile* profile_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserFrameWin);
-};
+#include "chrome/browser/ui/views/frame/browser_frame_win.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_WIN_H_
+
diff --git a/chrome/browser/views/frame/browser_non_client_frame_view.h b/chrome/browser/views/frame/browser_non_client_frame_view.h
index ba8ba40..38b6cfd 100644
--- a/chrome/browser/views/frame/browser_non_client_frame_view.h
+++ b/chrome/browser/views/frame/browser_non_client_frame_view.h
@@ -6,28 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_
#pragma once
-#include "views/window/non_client_view.h"
-
-class BaseTabStrip;
-
-// A specialization of the NonClientFrameView object that provides additional
-// Browser-specific methods.
-class BrowserNonClientFrameView : public views::NonClientFrameView {
- public:
- BrowserNonClientFrameView() : NonClientFrameView() {}
- virtual ~BrowserNonClientFrameView() {}
-
- // Returns the bounds within which the TabStrip should be laid out.
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const = 0;
-
- // Returns the y coordinate within the window at which the horizontal TabStrip
- // begins, or (in vertical tabs mode) would begin. If |restored| is true,
- // this is calculated as if we were in restored mode regardless of the current
- // mode. This is used to correctly align theme images.
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const = 0;
-
- // Updates the throbber.
- virtual void UpdateThrobber(bool running) = 0;
-};
+#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_
+
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
deleted file mode 100644
index e423603..0000000
--- a/chrome/browser/views/frame/browser_root_view.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_root_view.h"
-
-#include "app/drag_drop_types.h"
-#include "app/l10n_util.h"
-#include "app/os_exchange_data.h"
-#include "chrome/browser/autocomplete/autocomplete.h"
-#include "chrome/browser/autocomplete/autocomplete_classifier.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "chrome/browser/location_bar.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "grit/chromium_strings.h"
-
-BrowserRootView::BrowserRootView(BrowserView* browser_view,
- views::Widget* widget)
- : views::RootView(widget),
- browser_view_(browser_view),
- forwarding_to_tab_strip_(false) {
- SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME));
-}
-
-bool BrowserRootView::GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats) {
- if (tabstrip() && tabstrip()->IsVisible() && !tabstrip()->IsAnimating()) {
- *formats = OSExchangeData::URL | OSExchangeData::STRING;
- return true;
- }
- return false;
-}
-
-bool BrowserRootView::AreDropTypesRequired() {
- return true;
-}
-
-bool BrowserRootView::CanDrop(const OSExchangeData& data) {
- if (!tabstrip() || !tabstrip()->IsVisible() || tabstrip()->IsAnimating())
- return false;
-
- // If there is a URL, we'll allow the drop.
- if (data.HasURL())
- return true;
-
- // If there isn't a URL, see if we can 'paste and go'.
- return GetPasteAndGoURL(data, NULL);
-}
-
-void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
- if (ShouldForwardToTabStrip(event)) {
- forwarding_to_tab_strip_ = true;
- scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event, event.GetData()));
- tabstrip()->OnDragEntered(*mapped_event.get());
- }
-}
-
-int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
- if (ShouldForwardToTabStrip(event)) {
- scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event, event.GetData()));
- if (!forwarding_to_tab_strip_) {
- tabstrip()->OnDragEntered(*mapped_event.get());
- forwarding_to_tab_strip_ = true;
- }
- return tabstrip()->OnDragUpdated(*mapped_event.get());
- } else if (forwarding_to_tab_strip_) {
- forwarding_to_tab_strip_ = false;
- tabstrip()->OnDragExited();
- }
- return DragDropTypes::DRAG_NONE;
-}
-
-void BrowserRootView::OnDragExited() {
- if (forwarding_to_tab_strip_) {
- forwarding_to_tab_strip_ = false;
- tabstrip()->OnDragExited();
- }
-}
-
-int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) {
- if (!forwarding_to_tab_strip_)
- return DragDropTypes::DRAG_NONE;
-
- // Extract the URL and create a new OSExchangeData containing the URL. We do
- // this as the TabStrip doesn't know about the autocomplete edit and neeeds
- // to know about it to handle 'paste and go'.
- GURL url;
- std::wstring title;
- OSExchangeData mapped_data;
- if (!event.GetData().GetURLAndTitle(&url, &title) || !url.is_valid()) {
- // The url isn't valid. Use the paste and go url.
- if (GetPasteAndGoURL(event.GetData(), &url))
- mapped_data.SetURL(url, std::wstring());
- // else case: couldn't extract a url or 'paste and go' url. This ends up
- // passing through an OSExchangeData with nothing in it. We need to do this
- // so that the tab strip cleans up properly.
- } else {
- mapped_data.SetURL(url, std::wstring());
- }
- forwarding_to_tab_strip_ = false;
- scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event, mapped_data));
- return tabstrip()->OnPerformDrop(*mapped_event);
-}
-
-bool BrowserRootView::ShouldForwardToTabStrip(
- const views::DropTargetEvent& event) {
- if (!tabstrip()->IsVisible())
- return false;
-
- // Allow the drop as long as the mouse is over the tabstrip or vertically
- // before it.
- gfx::Point tab_loc_in_host;
- ConvertPointToView(tabstrip(), this, &tab_loc_in_host);
- return event.y() < tab_loc_in_host.y() + tabstrip()->height();
-}
-
-views::DropTargetEvent* BrowserRootView::MapEventToTabStrip(
- const views::DropTargetEvent& event,
- const OSExchangeData& data) {
- gfx::Point tab_strip_loc(event.location());
- ConvertPointToView(this, tabstrip(), &tab_strip_loc);
- return new views::DropTargetEvent(data, tab_strip_loc.x(),
- tab_strip_loc.y(),
- event.GetSourceOperations());
-}
-
-BaseTabStrip* BrowserRootView::tabstrip() const {
- return browser_view_->tabstrip();
-}
-
-bool BrowserRootView::GetPasteAndGoURL(const OSExchangeData& data, GURL* url) {
- if (!data.HasString())
- return false;
-
- std::wstring text;
- if (!data.GetString(&text) || text.empty())
- return false;
-
- AutocompleteMatch match;
- browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify(
- text, std::wstring(), &match, NULL);
- if (!match.destination_url.is_valid())
- return false;
-
- if (url)
- *url = match.destination_url;
- return true;
-}
diff --git a/chrome/browser/views/frame/browser_root_view.h b/chrome/browser/views/frame/browser_root_view.h
index 4ae382a..bf129da 100644
--- a/chrome/browser/views/frame/browser_root_view.h
+++ b/chrome/browser/views/frame/browser_root_view.h
@@ -1,63 +1,13 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
-#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
+#ifndef CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_ROOT_VIEW_H_
+#define CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_ROOT_VIEW_H_
#pragma once
-#include "views/widget/root_view.h"
+#include "chrome/browser/ui/views/frame/browser_root_view.h"
+// TODO(beng): remove this file once all includes have been updated.
-class BrowserView;
-class OSExchangeData;
-class BaseTabStrip;
+#endif // CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_ROOT_VIEW_H_
-// RootView implementation used by BrowserFrame. This forwards drop events to
-// the TabStrip. Visually the tabstrip extends to the top of the frame, but in
-// actually it doesn't. The tabstrip is only as high as a tab. To enable
-// dropping above the tabstrip BrowserRootView forwards drop events to the
-// TabStrip.
-class BrowserRootView : public views::RootView {
- public:
- // You must call set_tabstrip before this class will accept drops.
- BrowserRootView(BrowserView* browser_view, views::Widget* widget);
-
- virtual bool GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
- virtual bool AreDropTypesRequired();
- virtual bool CanDrop(const OSExchangeData& data);
- virtual void OnDragEntered(const views::DropTargetEvent& event);
- virtual int OnDragUpdated(const views::DropTargetEvent& event);
- virtual void OnDragExited();
- virtual int OnPerformDrop(const views::DropTargetEvent& event);
-
- private:
- // Returns true if the event should be forwarded to the tabstrip.
- bool ShouldForwardToTabStrip(const views::DropTargetEvent& event);
-
- // Converts the event from the hosts coordinate system to the tabstrips
- // coordinate system.
- views::DropTargetEvent* MapEventToTabStrip(
- const views::DropTargetEvent& event,
- const OSExchangeData& data);
-
- inline BaseTabStrip* tabstrip() const;
-
- // Returns true if |data| has string contents and the user can "paste and go".
- // If |url| is non-NULL and the user can "paste and go", |url| is set to the
- // desired destination.
- bool GetPasteAndGoURL(const OSExchangeData& data, GURL* url);
-
- // The BrowserView.
- BrowserView* browser_view_;
-
- // If true, drag and drop events are being forwarded to the tab strip.
- // This is used to determine when to send OnDragEntered and OnDragExited
- // to the tab strip.
- bool forwarding_to_tab_strip_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserRootView);
-};
-
-#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
deleted file mode 100644
index 949b73b..0000000
--- a/chrome/browser/views/frame/browser_view.cc
+++ /dev/null
@@ -1,2472 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_view.h"
-
-#if defined(OS_LINUX)
-#include <gtk/gtk.h>
-#endif
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/command_line.h"
-#include "base/i18n/rtl.h"
-#include "base/string_number_conversions.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/app_modal_dialog_queue.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
-#include "chrome/browser/automation/ui_controls.h"
-#include "chrome/browser/bookmarks/bookmark_utils.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/debugger/devtools_window.h"
-#include "chrome/browser/dom_ui/bug_report_ui.h"
-#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/instant/instant_controller.h"
-#include "chrome/browser/ntp_background_util.h"
-#include "chrome/browser/page_info_window.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/sessions/tab_restore_service.h"
-#include "chrome/browser/sidebar/sidebar_container.h"
-#include "chrome/browser/sidebar/sidebar_manager.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_view.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
-#include "chrome/browser/themes/browser_theme_provider.h"
-#include "chrome/browser/view_ids.h"
-#include "chrome/browser/views/accessible_view_helper.h"
-#include "chrome/browser/views/bookmark_bar_view.h"
-#include "chrome/browser/views/browser_dialogs.h"
-#include "chrome/browser/views/default_search_view.h"
-#include "chrome/browser/views/download_shelf_view.h"
-#include "chrome/browser/views/frame/browser_view_layout.h"
-#include "chrome/browser/views/frame/contents_container.h"
-#include "chrome/browser/views/fullscreen_exit_bubble.h"
-#include "chrome/browser/views/status_bubble_views.h"
-#include "chrome/browser/views/tab_contents/tab_contents_container.h"
-#include "chrome/browser/views/tabs/browser_tab_strip_controller.h"
-#include "chrome/browser/views/tabs/side_tab_strip.h"
-#include "chrome/browser/views/theme_install_bubble_view.h"
-#include "chrome/browser/views/toolbar_view.h"
-#include "chrome/browser/views/update_recommended_message_box.h"
-#include "chrome/browser/views/window.h"
-#include "chrome/browser/window_sizer.h"
-#include "chrome/browser/wrench_menu_model.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/extension_resource.h"
-#include "chrome/common/native_window_notification_source.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/url_constants.h"
-#include "gfx/canvas_skia.h"
-#include "grit/app_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "grit/webkit_resources.h"
-#include "views/controls/single_split_view.h"
-#include "views/focus/external_focus_tracker.h"
-#include "views/focus/view_storage.h"
-#include "views/grid_layout.h"
-#include "views/widget/root_view.h"
-#include "views/window/dialog_delegate.h"
-#include "views/window/window.h"
-
-#if defined(OS_WIN)
-#include "app/win_util.h"
-#include "chrome/browser/aeropeek_manager.h"
-#include "chrome/browser/jumplist_win.h"
-#elif defined(OS_LINUX)
-#include "chrome/browser/views/accelerator_table_gtk.h"
-#include "views/window/hit_test.h"
-#include "views/window/window_gtk.h"
-#endif
-
-using base::TimeDelta;
-using views::ColumnSet;
-using views::GridLayout;
-
-// The height of the status bubble.
-static const int kStatusBubbleHeight = 20;
-// The name of a key to store on the window handle so that other code can
-// locate this object using just the handle.
-#if defined(OS_WIN)
-static const wchar_t* kBrowserViewKey = L"__BROWSER_VIEW__";
-#else
-static const char* kBrowserViewKey = "__BROWSER_VIEW__";
-#endif
-// How frequently we check for hung plugin windows.
-static const int kDefaultHungPluginDetectFrequency = 2000;
-// How long do we wait before we consider a window hung (in ms).
-static const int kDefaultPluginMessageResponseTimeout = 30000;
-// The number of milliseconds between loading animation frames.
-static const int kLoadingAnimationFrameTimeMs = 30;
-// The amount of space we expect the window border to take up.
-static const int kWindowBorderWidth = 5;
-
-// If not -1, windows are shown with this state.
-static int explicit_show_state = -1;
-
-// How round the 'new tab' style bookmarks bar is.
-static const int kNewtabBarRoundness = 5;
-// ------------
-
-// Returned from BrowserView::GetClassName.
-const char BrowserView::kViewClassName[] = "browser/views/BrowserView";
-
-#if defined(OS_CHROMEOS)
-// Get a normal browser window of given |profile| to use as dialog parent
-// if given |browser| is not one. Otherwise, returns browser window of
-// |browser|. If |profile| is NULL, |browser|'s profile is used to find the
-// normal browser.
-static gfx::NativeWindow GetNormalBrowserWindowForBrowser(Browser* browser,
- Profile* profile) {
- if (browser->type() != Browser::TYPE_NORMAL) {
- Browser* normal_browser = BrowserList::FindBrowserWithType(
- profile ? profile : browser->profile(),
- Browser::TYPE_NORMAL, true);
- if (normal_browser && normal_browser->window())
- return normal_browser->window()->GetNativeHandle();
- }
-
- return browser->window()->GetNativeHandle();
-}
-#endif // defined(OS_CHROMEOS)
-
-///////////////////////////////////////////////////////////////////////////////
-// BookmarkExtensionBackground, private:
-// This object serves as the views::Background object which is used to layout
-// and paint the bookmark bar.
-class BookmarkExtensionBackground : public views::Background {
- public:
- explicit BookmarkExtensionBackground(BrowserView* browser_view,
- DetachableToolbarView* host_view,
- Browser* browser);
-
- // View methods overridden from views:Background.
- virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
-
- private:
- BrowserView* browser_view_;
-
- // The view hosting this background.
- DetachableToolbarView* host_view_;
-
- Browser* browser_;
-
- DISALLOW_COPY_AND_ASSIGN(BookmarkExtensionBackground);
-};
-
-BookmarkExtensionBackground::BookmarkExtensionBackground(
- BrowserView* browser_view,
- DetachableToolbarView* host_view,
- Browser* browser)
- : browser_view_(browser_view),
- host_view_(host_view),
- browser_(browser) {
-}
-
-void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas,
- views::View* view) const {
- ThemeProvider* tp = host_view_->GetThemeProvider();
- int toolbar_overlap = host_view_->GetToolbarOverlap();
- // The client edge is drawn below the toolbar bounds.
- if (toolbar_overlap)
- toolbar_overlap += views::NonClientFrameView::kClientEdgeThickness;
- if (host_view_->IsDetached()) {
- // Draw the background to match the new tab page.
- int height = 0;
- TabContents* contents = browser_->GetSelectedTabContents();
- if (contents && contents->view())
- height = contents->view()->GetContainerSize().height();
- NtpBackgroundUtil::PaintBackgroundDetachedMode(
- host_view_->GetThemeProvider(), canvas,
- gfx::Rect(0, toolbar_overlap, host_view_->width(),
- host_view_->height() - toolbar_overlap), height);
-
- // As 'hidden' according to the animation is the full in-tab state,
- // we invert the value - when current_state is at '0', we expect the
- // bar to be docked.
- double current_state = 1 - host_view_->GetAnimationValue();
- double h_padding =
- static_cast<double>(BookmarkBarView::kNewtabHorizontalPadding) *
- current_state;
- double v_padding =
- static_cast<double>(BookmarkBarView::kNewtabVerticalPadding) *
- current_state;
-
- SkRect rect;
- double roundness = 0;
- DetachableToolbarView::CalculateContentArea(current_state, h_padding,
- v_padding, &rect, &roundness, host_view_);
- DetachableToolbarView::PaintContentAreaBackground(canvas, tp, rect,
- roundness);
- DetachableToolbarView::PaintContentAreaBorder(canvas, tp, rect, roundness);
- if (!toolbar_overlap)
- DetachableToolbarView::PaintHorizontalBorder(canvas, host_view_);
- } else {
- DetachableToolbarView::PaintBackgroundAttachedMode(canvas, host_view_,
- browser_view_->OffsetPointForToolbarBackgroundImage(
- gfx::Point(host_view_->MirroredX(), host_view_->y())));
- if (host_view_->height() >= toolbar_overlap)
- DetachableToolbarView::PaintHorizontalBorder(canvas, host_view_);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ResizeCorner, private:
-
-class ResizeCorner : public views::View {
- public:
- ResizeCorner() {
- EnableCanvasFlippingForRTLUI(true);
- }
-
- virtual void Paint(gfx::Canvas* canvas) {
- views::Window* window = GetWindow();
- if (!window || (window->IsMaximized() || window->IsFullscreen()))
- return;
-
- SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_TEXTAREA_RESIZER);
- bitmap->buildMipMap(false);
- canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(),
- height() - bitmap->height());
- }
-
- static gfx::Size GetSize() {
- // This is disabled until we find what makes us slower when we let
- // WebKit know that we have a resizer rect...
- // int scrollbar_thickness = gfx::scrollbar_size();
- // return gfx::Size(scrollbar_thickness, scrollbar_thickness);
- return gfx::Size();
- }
-
- virtual gfx::Size GetPreferredSize() {
- views::Window* window = GetWindow();
- return (!window || window->IsMaximized() || window->IsFullscreen()) ?
- gfx::Size() : GetSize();
- }
-
- virtual void Layout() {
- views::View* parent_view = GetParent();
- if (parent_view) {
- gfx::Size ps = GetPreferredSize();
- // No need to handle Right to left text direction here,
- // our parent must take care of it for us...
- SetBounds(parent_view->width() - ps.width(),
- parent_view->height() - ps.height(), ps.width(), ps.height());
- }
- }
-
- private:
- // Returns the WindowWin we're displayed in. Returns NULL if we're not
- // currently in a window.
- views::Window* GetWindow() {
- views::Widget* widget = GetWidget();
- return widget ? widget->GetWindow() : NULL;
- }
-
- DISALLOW_COPY_AND_ASSIGN(ResizeCorner);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// DownloadInProgressConfirmDialogDelegate
-
-class DownloadInProgressConfirmDialogDelegate : public views::DialogDelegate,
- public views::View {
- public:
- explicit DownloadInProgressConfirmDialogDelegate(Browser* browser)
- : browser_(browser),
- product_name_(l10n_util::GetString(IDS_PRODUCT_NAME)) {
- int download_count = browser->profile()->GetDownloadManager()->
- in_progress_count();
-
- std::wstring warning_text;
- std::wstring explanation_text;
- if (download_count == 1) {
- warning_text =
- l10n_util::GetStringF(IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING,
- product_name_);
- explanation_text =
- l10n_util::GetStringF(IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION,
- product_name_);
- ok_button_text_ = l10n_util::GetString(
- IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
- cancel_button_text_ = l10n_util::GetString(
- IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
- } else {
- warning_text =
- l10n_util::GetStringF(IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING,
- product_name_,
- UTF8ToWide(base::IntToString(download_count)));
- explanation_text =
- l10n_util::GetStringF(
- IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION, product_name_);
- ok_button_text_ = l10n_util::GetString(
- IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL);
- cancel_button_text_ = l10n_util::GetString(
- IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
- }
-
- // There are two lines of text: the bold warning label and the text
- // explanation label.
- GridLayout* layout = new GridLayout(this);
- SetLayoutManager(layout);
- const int columnset_id = 0;
- ColumnSet* column_set = layout->AddColumnSet(columnset_id);
- column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1,
- GridLayout::USE_PREF, 0, 0);
-
- gfx::Font bold_font =
- ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD);
- warning_ = new views::Label(warning_text, bold_font);
- warning_->SetMultiLine(true);
- warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- warning_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10));
- layout->StartRow(0, columnset_id);
- layout->AddView(warning_);
-
- explanation_ = new views::Label(explanation_text);
- explanation_->SetMultiLine(true);
- explanation_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- explanation_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10));
- layout->StartRow(0, columnset_id);
- layout->AddView(explanation_);
-
- dialog_dimensions_ = views::Window::GetLocalizedContentsSize(
- IDS_DOWNLOAD_IN_PROGRESS_WIDTH_CHARS,
- IDS_DOWNLOAD_IN_PROGRESS_MINIMUM_HEIGHT_LINES);
- const int height =
- warning_->GetHeightForWidth(dialog_dimensions_.width()) +
- explanation_->GetHeightForWidth(dialog_dimensions_.width());
- dialog_dimensions_.set_height(std::max(height,
- dialog_dimensions_.height()));
- }
-
- ~DownloadInProgressConfirmDialogDelegate() {
- }
-
- // View implementation:
- virtual gfx::Size GetPreferredSize() {
- return dialog_dimensions_;
- }
-
- // DialogDelegate implementation:
- virtual int GetDefaultDialogButton() const {
- return MessageBoxFlags::DIALOGBUTTON_CANCEL;
- }
-
- virtual std::wstring GetDialogButtonLabel(
- MessageBoxFlags::DialogButton button) const {
- if (button == MessageBoxFlags::DIALOGBUTTON_OK)
- return ok_button_text_;
-
- DCHECK_EQ(MessageBoxFlags::DIALOGBUTTON_CANCEL, button);
- return cancel_button_text_;
- }
-
- virtual bool Accept() {
- browser_->InProgressDownloadResponse(true);
- return true;
- }
-
- virtual bool Cancel() {
- browser_->InProgressDownloadResponse(false);
- return true;
- }
-
- // WindowDelegate implementation:
- virtual bool IsModal() const { return true; }
-
- virtual views::View* GetContentsView() {
- return this;
- }
-
- virtual std::wstring GetWindowTitle() const {
- return product_name_;
- }
-
- private:
- Browser* browser_;
- views::Label* warning_;
- views::Label* explanation_;
-
- std::wstring ok_button_text_;
- std::wstring cancel_button_text_;
-
- std::wstring product_name_;
-
- gfx::Size dialog_dimensions_;
-
- DISALLOW_COPY_AND_ASSIGN(DownloadInProgressConfirmDialogDelegate);
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, public:
-
-// static
-void BrowserView::SetShowState(int state) {
- explicit_show_state = state;
-}
-
-BrowserView::BrowserView(Browser* browser)
- : views::ClientView(NULL, NULL),
- last_focused_view_storage_id_(
- views::ViewStorage::GetSharedInstance()->CreateStorageID()),
- frame_(NULL),
- browser_(browser),
- active_bookmark_bar_(NULL),
- tabstrip_(NULL),
- toolbar_(NULL),
- infobar_container_(NULL),
- sidebar_container_(NULL),
- sidebar_split_(NULL),
- contents_container_(NULL),
- devtools_container_(NULL),
- preview_container_(NULL),
- contents_(NULL),
- contents_split_(NULL),
- initialized_(false),
- ignore_layout_(true)
-#if defined(OS_WIN)
- , hung_window_detector_(&hung_plugin_action_),
- ticker_(0)
-#endif
- {
- browser_->tabstrip_model()->AddObserver(this);
-
- registrar_.Add(this,
- NotificationType::SIDEBAR_CHANGED,
- Source<SidebarManager>(SidebarManager::GetInstance()));
-}
-
-BrowserView::~BrowserView() {
- browser_->tabstrip_model()->RemoveObserver(this);
-
-#if defined(OS_WIN)
- // Remove this observer.
- if (aeropeek_manager_.get())
- browser_->tabstrip_model()->RemoveObserver(aeropeek_manager_.get());
-
- // Stop hung plugin monitoring.
- ticker_.Stop();
- ticker_.UnregisterTickHandler(&hung_window_detector_);
-#endif
-
- // We destroy the download shelf before |browser_| to remove its child
- // download views from the set of download observers (since the observed
- // downloads can be destroyed along with |browser_| and the observer
- // notifications will call back into deleted objects).
- download_shelf_.reset();
-
- // The TabStrip attaches a listener to the model. Make sure we shut down the
- // TabStrip first so that it can cleanly remove the listener.
- tabstrip_->GetParent()->RemoveChildView(tabstrip_);
- delete tabstrip_;
- tabstrip_ = NULL;
-
- // Explicitly set browser_ to NULL.
- browser_.reset();
-}
-
-// static
-BrowserView* BrowserView::GetBrowserViewForNativeWindow(
- gfx::NativeWindow window) {
-#if defined(OS_WIN)
- if (IsWindow(window)) {
- HANDLE data = GetProp(window, kBrowserViewKey);
- if (data)
- return reinterpret_cast<BrowserView*>(data);
- }
-#else
- if (window) {
- return static_cast<BrowserView*>(
- g_object_get_data(G_OBJECT(window), kBrowserViewKey));
- }
-#endif
- return NULL;
-}
-
-int BrowserView::GetShowState() const {
- if (explicit_show_state != -1)
- return explicit_show_state;
-
-#if defined(OS_WIN)
- STARTUPINFO si = {0};
- si.cb = sizeof(si);
- si.dwFlags = STARTF_USESHOWWINDOW;
- GetStartupInfo(&si);
- return si.wShowWindow;
-#else
- NOTIMPLEMENTED();
- return 0;
-#endif
-}
-
-void BrowserView::WindowMoved() {
- // Cancel any tabstrip animations, some of them may be invalidated by the
- // window being repositioned.
- // Comment out for one cycle to see if this fixes dist tests.
- // tabstrip_->DestroyDragController();
-
- status_bubble_->Reposition();
-
- BrowserBubbleHost::WindowMoved();
-
- browser::HideBookmarkBubbleView();
-
- // Close the omnibox popup, if any.
- if (toolbar_->location_bar())
- toolbar_->location_bar()->location_entry()->ClosePopup();
-}
-
-void BrowserView::WindowMoveOrResizeStarted() {
- TabContents* tab_contents = GetSelectedTabContents();
- if (tab_contents)
- tab_contents->WindowMoveOrResizeStarted();
-}
-
-gfx::Rect BrowserView::GetToolbarBounds() const {
- gfx::Rect toolbar_bounds(toolbar_->bounds());
- if (toolbar_bounds.IsEmpty())
- return toolbar_bounds;
- // When using vertical tabs, the toolbar appears to extend behind the tab
- // column.
- if (UseVerticalTabs())
- toolbar_bounds.Inset(tabstrip_->x() - toolbar_bounds.x(), 0, 0, 0);
- // The apparent toolbar edges are outside the "real" toolbar edges.
- toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
- return toolbar_bounds;
-}
-
-gfx::Rect BrowserView::GetClientAreaBounds() const {
- gfx::Rect container_bounds = contents_->bounds();
- gfx::Point container_origin = container_bounds.origin();
- ConvertPointToView(this, GetParent(), &container_origin);
- container_bounds.set_origin(container_origin);
- return container_bounds;
-}
-
-gfx::Rect BrowserView::GetFindBarBoundingBox() const {
- return GetBrowserViewLayout()->GetFindBarBoundingBox();
-}
-
-int BrowserView::GetTabStripHeight() const {
- // We want to return tabstrip_->height(), but we might be called in the midst
- // of layout, when that hasn't yet been updated to reflect the current state.
- // So return what the tabstrip height _ought_ to be right now.
- return IsTabStripVisible() ? tabstrip_->GetPreferredSize().height() : 0;
-}
-
-gfx::Point BrowserView::OffsetPointForToolbarBackgroundImage(
- const gfx::Point& point) const {
- // The background image starts tiling horizontally at the window left edge and
- // vertically at the top edge of the horizontal tab strip (or where it would
- // be). We expect our parent's origin to be the window origin.
- gfx::Point window_point(point.Add(gfx::Point(MirroredX(), y())));
- window_point.Offset(0, -frame_->GetHorizontalTabStripVerticalOffset(false));
- return window_point;
-}
-
-int BrowserView::GetSidebarWidth() const {
- if (!sidebar_container_ || !sidebar_container_->IsVisible())
- return 0;
- return sidebar_split_->divider_offset();
-}
-
-bool BrowserView::IsTabStripVisible() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
-}
-
-bool BrowserView::UseVerticalTabs() const {
- return browser_->tabstrip_model()->delegate()->UseVerticalTabs();
-}
-
-bool BrowserView::IsOffTheRecord() const {
- return browser_->profile()->IsOffTheRecord();
-}
-
-bool BrowserView::ShouldShowOffTheRecordAvatar() const {
- return IsOffTheRecord() && IsBrowserTypeNormal();
-}
-
-bool BrowserView::AcceleratorPressed(const views::Accelerator& accelerator) {
- std::map<views::Accelerator, int>::const_iterator iter =
- accelerator_table_.find(accelerator);
- DCHECK(iter != accelerator_table_.end());
-
- int command_id = iter->second;
- if (browser_->command_updater()->SupportsCommand(command_id) &&
- browser_->command_updater()->IsCommandEnabled(command_id)) {
- browser_->ExecuteCommand(command_id);
- return true;
- }
- return false;
-}
-
-bool BrowserView::GetAccelerator(int cmd_id, menus::Accelerator* accelerator) {
- // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators
- // anywhere so we need to check for them explicitly here.
- switch (cmd_id) {
- case IDC_CUT:
- *accelerator = views::Accelerator(app::VKEY_X, false, true, false);
- return true;
- case IDC_COPY:
- *accelerator = views::Accelerator(app::VKEY_C, false, true, false);
- return true;
- case IDC_PASTE:
- *accelerator = views::Accelerator(app::VKEY_V, false, true, false);
- return true;
- }
- // Else, we retrieve the accelerator information from the accelerator table.
- std::map<views::Accelerator, int>::iterator it =
- accelerator_table_.begin();
- for (; it != accelerator_table_.end(); ++it) {
- if (it->second == cmd_id) {
- *accelerator = it->first;
- return true;
- }
- }
- return false;
-}
-
-bool BrowserView::ActivateAppModalDialog() const {
- // If another browser is app modal, flash and activate the modal browser.
- if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) {
- Browser* active_browser = BrowserList::GetLastActive();
- if (active_browser && (browser_ != active_browser)) {
- active_browser->window()->FlashFrame();
- active_browser->window()->Activate();
- }
- Singleton<AppModalDialogQueue>()->ActivateModalDialog();
- return true;
- }
- return false;
-}
-
-void BrowserView::ActivationChanged(bool activated) {
- if (activated)
- BrowserList::SetLastActive(browser_.get());
-}
-
-TabContents* BrowserView::GetSelectedTabContents() const {
- return browser_->GetSelectedTabContents();
-}
-
-SkBitmap BrowserView::GetOTRAvatarIcon() {
- static SkBitmap* otr_avatar_ = new SkBitmap();
-
- if (otr_avatar_->isNull()) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- *otr_avatar_ = *rb.GetBitmapNamed(IDR_OTR_ICON);
- }
- return *otr_avatar_;
-}
-
-#if defined(OS_WIN)
-void BrowserView::PrepareToRunSystemMenu(HMENU menu) {
- system_menu_->UpdateStates();
-}
-#endif
-
-// static
-void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) {
- prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout,
- kDefaultPluginMessageResponseTimeout);
- prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency,
- kDefaultHungPluginDetectFrequency);
-}
-
-bool BrowserView::IsPositionInWindowCaption(const gfx::Point& point) {
- return GetBrowserViewLayout()->IsPositionInWindowCaption(point);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, BrowserWindow implementation:
-
-void BrowserView::Show() {
- // If the window is already visible, just activate it.
- if (frame_->GetWindow()->IsVisible()) {
- frame_->GetWindow()->Activate();
- return;
- }
-
- // Setting the focus doesn't work when the window is invisible, so any focus
- // initialization that happened before this will be lost.
- //
- // We really "should" restore the focus whenever the window becomes unhidden,
- // but I think initializing is the only time where this can happen where
- // there is some focus change we need to pick up, and this is easier than
- // plumbing through an un-hide message all the way from the frame.
- //
- // If we do find there are cases where we need to restore the focus on show,
- // that should be added and this should be removed.
- RestoreFocus();
-
- frame_->GetWindow()->Show();
-}
-
-void BrowserView::SetBounds(const gfx::Rect& bounds) {
- GetWidget()->SetBounds(bounds);
-}
-
-void BrowserView::Close() {
- BrowserBubbleHost::Close();
-
- frame_->GetWindow()->Close();
-}
-
-void BrowserView::Activate() {
- frame_->GetWindow()->Activate();
-}
-
-void BrowserView::Deactivate() {
- frame_->GetWindow()->Deactivate();
-}
-
-bool BrowserView::IsActive() const {
- return frame_->GetWindow()->IsActive();
-}
-
-void BrowserView::FlashFrame() {
-#if defined(OS_WIN)
- FLASHWINFO fwi;
- fwi.cbSize = sizeof(fwi);
- fwi.hwnd = frame_->GetWindow()->GetNativeWindow();
- fwi.dwFlags = FLASHW_ALL;
- fwi.uCount = 4;
- fwi.dwTimeout = 0;
- FlashWindowEx(&fwi);
-#else
- // Doesn't matter for chrome os.
-#endif
-}
-
-gfx::NativeWindow BrowserView::GetNativeHandle() {
- return GetWidget()->GetWindow()->GetNativeWindow();
-}
-
-BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() {
- return this;
-}
-
-StatusBubble* BrowserView::GetStatusBubble() {
- return status_bubble_.get();
-}
-
-void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) {
- if (is_animating) {
- contents_container_->SetFastResize(true);
- UpdateUIForContents(browser_->GetSelectedTabContents());
- contents_container_->SetFastResize(false);
- } else {
- UpdateUIForContents(browser_->GetSelectedTabContents());
- // When transitioning from animating to not animating we need to make sure
- // the contents_container_ gets layed out. If we don't do this and the
- // bounds haven't changed contents_container_ won't get a Layout out and
- // we'll end up with a gray rect because the clip wasn't updated.
- contents_container_->InvalidateLayout();
- contents_split_->Layout();
- }
-}
-
-void BrowserView::UpdateTitleBar() {
- frame_->GetWindow()->UpdateWindowTitle();
- if (ShouldShowWindowIcon() && !loading_animation_timer_.IsRunning())
- frame_->GetWindow()->UpdateWindowIcon();
-}
-
-void BrowserView::ShelfVisibilityChanged() {
- Layout();
-}
-
-void BrowserView::UpdateDevTools() {
- UpdateDevToolsForContents(GetSelectedTabContents());
- Layout();
-}
-
-void BrowserView::UpdateLoadingAnimations(bool should_animate) {
- if (should_animate) {
- if (!loading_animation_timer_.IsRunning()) {
- // Loads are happening, and the timer isn't running, so start it.
- loading_animation_timer_.Start(
- TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
- &BrowserView::LoadingAnimationCallback);
- }
- } else {
- if (loading_animation_timer_.IsRunning()) {
- loading_animation_timer_.Stop();
- // Loads are now complete, update the state if a task was scheduled.
- LoadingAnimationCallback();
- }
- }
-}
-
-void BrowserView::SetStarredState(bool is_starred) {
- toolbar_->location_bar()->SetStarToggled(is_starred);
-}
-
-gfx::Rect BrowserView::GetRestoredBounds() const {
- return frame_->GetWindow()->GetNormalBounds();
-}
-
-bool BrowserView::IsMaximized() const {
- return frame_->GetWindow()->IsMaximized();
-}
-
-void BrowserView::SetFullscreen(bool fullscreen) {
- if (IsFullscreen() == fullscreen)
- return; // Nothing to do.
-
-#if defined(OS_WIN)
- ProcessFullscreen(fullscreen);
-#else
- // On Linux changing fullscreen is async. Ask the window to change it's
- // fullscreen state, and when done invoke ProcessFullscreen.
- frame_->GetWindow()->SetFullscreen(fullscreen);
-#endif
-}
-
-bool BrowserView::IsFullscreen() const {
- return frame_->GetWindow()->IsFullscreen();
-}
-
-bool BrowserView::IsFullscreenBubbleVisible() const {
- return fullscreen_bubble_.get() ? true : false;
-}
-
-void BrowserView::FullScreenStateChanged() {
- ProcessFullscreen(IsFullscreen());
-}
-
-void BrowserView::RestoreFocus() {
- TabContents* selected_tab_contents = GetSelectedTabContents();
- if (selected_tab_contents)
- selected_tab_contents->view()->RestoreFocus();
-}
-
-LocationBar* BrowserView::GetLocationBar() const {
- return toolbar_->location_bar();
-}
-
-void BrowserView::SetFocusToLocationBar(bool select_all) {
- LocationBarView* location_bar = toolbar_->location_bar();
- if (location_bar->IsFocusableInRootView()) {
- // Location bar got focus.
- location_bar->FocusLocation(select_all);
- } else {
- // If none of location bar/compact navigation bar got focus,
- // then clear focus.
- views::FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
- focus_manager->ClearFocus();
- }
-}
-
-void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
- toolbar_->reload_button()->ChangeMode(
- is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force);
-}
-
-void BrowserView::UpdateToolbar(TabContents* contents,
- bool should_restore_state) {
- toolbar_->Update(contents, should_restore_state);
-}
-
-void BrowserView::FocusToolbar() {
- // Start the traversal within the main toolbar, passing it the storage id
- // of the view where focus should be returned if the user exits the toolbar.
- SaveFocusedView();
- toolbar_->SetPaneFocus(last_focused_view_storage_id_, NULL);
-}
-
-void BrowserView::FocusBookmarksToolbar() {
- if (active_bookmark_bar_ && bookmark_bar_view_->IsVisible()) {
- SaveFocusedView();
- bookmark_bar_view_->SetPaneFocus(last_focused_view_storage_id_, NULL);
- }
-}
-
-void BrowserView::FocusAppMenu() {
- // Chrome doesn't have a traditional menu bar, but it has a menu button in the
- // main toolbar that plays the same role. If the user presses a key that
- // would typically focus the menu bar, tell the toolbar to focus the menu
- // button. If the user presses the key again, return focus to the previous
- // location.
- //
- // Not used on the Mac, which has a normal menu bar.
- if (toolbar_->IsAppMenuFocused()) {
- RestoreFocus();
- } else {
- SaveFocusedView();
- toolbar_->SetPaneFocusAndFocusAppMenu(last_focused_view_storage_id_);
- }
-}
-
-void BrowserView::RotatePaneFocus(bool forwards) {
- // This gets called when the user presses F6 (forwards) or Shift+F6
- // (backwards) to rotate to the next pane. Here, our "panes" are the
- // tab contents and each of our accessible toolbars, infobars, downloads
- // shelf, etc. When a pane has focus, all of its controls are accessible
- // in the tab traversal, and the tab traversal is "trapped" within that pane.
- //
- // Get a vector of all panes in the order we want them to be focused,
- // with NULL to represent the tab contents getting focus. If one of these
- // is currently invisible or has no focusable children it will be
- // automatically skipped.
- std::vector<AccessiblePaneView*> accessible_panes;
- GetAccessiblePanes(&accessible_panes);
- int pane_count = static_cast<int>(accessible_panes.size());
-
- std::vector<views::View*> accessible_views(
- accessible_panes.begin(), accessible_panes.end());
- accessible_views.push_back(GetTabContentsContainerView());
- if (sidebar_container_ && sidebar_container_->IsVisible())
- accessible_views.push_back(GetSidebarContainerView());
- if (devtools_container_->IsVisible())
- accessible_views.push_back(devtools_container_->GetFocusView());
- int count = static_cast<int>(accessible_views.size());
-
- // Figure out which view (if any) currently has the focus.
- views::View* focused_view = GetRootView()->GetFocusedView();
- int index = -1;
- if (focused_view) {
- for (int i = 0; i < count; ++i) {
- if (accessible_views[i] == focused_view ||
- accessible_views[i]->IsParentOf(focused_view)) {
- index = i;
- break;
- }
- }
- }
-
- // If the focus isn't currently in a pane, save the focus so we
- // can restore it if the user presses Escape.
- if (focused_view && index >= pane_count)
- SaveFocusedView();
-
- // Try to focus the next pane; if SetPaneFocusAndFocusDefault returns
- // false it means the pane didn't have any focusable controls, so skip
- // it and try the next one.
- for (;;) {
- if (forwards)
- index = (index + 1) % count;
- else
- index = ((index - 1) + count) % count;
-
- if (index < pane_count) {
- if (accessible_panes[index]->SetPaneFocusAndFocusDefault(
- last_focused_view_storage_id_)) {
- break;
- }
- } else {
- accessible_views[index]->RequestFocus();
- break;
- }
- }
-}
-
-void BrowserView::SaveFocusedView() {
- views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
- if (view_storage->RetrieveView(last_focused_view_storage_id_))
- view_storage->RemoveView(last_focused_view_storage_id_);
- views::View* focused_view = GetRootView()->GetFocusedView();
- if (focused_view)
- view_storage->StoreView(last_focused_view_storage_id_, focused_view);
-}
-
-void BrowserView::DestroyBrowser() {
- // Explicitly delete the BookmarkBarView now. That way we don't have to
- // worry about the BookmarkBarView potentially outliving the Browser &
- // Profile.
- bookmark_bar_view_.reset();
- browser_.reset();
-}
-
-bool BrowserView::IsBookmarkBarVisible() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) &&
- active_bookmark_bar_ &&
- (active_bookmark_bar_->GetPreferredSize().height() != 0);
-}
-
-bool BrowserView::IsBookmarkBarAnimating() const {
- return bookmark_bar_view_.get() && bookmark_bar_view_->is_animating();
-}
-
-bool BrowserView::IsToolbarVisible() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
- browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
-}
-
-gfx::Rect BrowserView::GetRootWindowResizerRect() const {
- if (frame_->GetWindow()->IsMaximized() || frame_->GetWindow()->IsFullscreen())
- return gfx::Rect();
-
- // We don't specify a resize corner size if we have a bottom shelf either.
- // This is because we take care of drawing the resize corner on top of that
- // shelf, so we don't want others to do it for us in this case.
- // Currently, the only visible bottom shelf is the download shelf.
- // Other tests should be added here if we add more bottom shelves.
- if (download_shelf_.get() && download_shelf_->IsShowing()) {
- return gfx::Rect();
- }
-
- gfx::Rect client_rect = contents_split_->bounds();
- gfx::Size resize_corner_size = ResizeCorner::GetSize();
- int x = client_rect.width() - resize_corner_size.width();
- if (base::i18n::IsRTL())
- x = 0;
- return gfx::Rect(x, client_rect.height() - resize_corner_size.height(),
- resize_corner_size.width(), resize_corner_size.height());
-}
-
-void BrowserView::DisableInactiveFrame() {
-#if defined(OS_WIN)
- frame_->GetWindow()->DisableInactiveRendering();
-#endif // No tricks are needed to get the right behavior on Linux.
-}
-
-void BrowserView::ConfirmSetDefaultSearchProvider(
- TabContents* tab_contents,
- TemplateURL* template_url,
- TemplateURLModel* template_url_model) {
-#if defined(OS_WIN)
- DefaultSearchView::Show(tab_contents, template_url, template_url_model);
-#else
- // TODO(levin): Implement for other platforms. Right now this is behind
- // a command line flag which is off.
-#endif
-}
-
-void BrowserView::ConfirmAddSearchProvider(const TemplateURL* template_url,
- Profile* profile) {
- browser::EditSearchEngine(GetWindow()->GetNativeWindow(), template_url, NULL,
- profile);
-}
-
-void BrowserView::ToggleBookmarkBar() {
- bookmark_utils::ToggleWhenVisible(browser_->profile());
-}
-
-views::Window* BrowserView::ShowAboutChromeDialog() {
- return browser::ShowAboutChromeView(GetWindow()->GetNativeWindow(),
- browser_->profile());
-}
-
-void BrowserView::ShowUpdateChromeDialog() {
- UpdateRecommendedMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow());
-}
-
-void BrowserView::ShowTaskManager() {
- browser::ShowTaskManager();
-}
-
-void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
- toolbar_->location_bar()->ShowStarBubble(url, !already_bookmarked);
-}
-
-void BrowserView::SetDownloadShelfVisible(bool visible) {
- // This can be called from the superclass destructor, when it destroys our
- // child views. At that point, browser_ is already gone.
- if (browser_ == NULL)
- return;
-
- if (visible && IsDownloadShelfVisible() != visible) {
- // Invoke GetDownloadShelf to force the shelf to be created.
- GetDownloadShelf();
- }
-
- if (browser_ != NULL)
- browser_->UpdateDownloadShelfVisibility(visible);
-
- // SetDownloadShelfVisible can force-close the shelf, so make sure we lay out
- // everything correctly, as if the animation had finished. This doesn't
- // matter for showing the shelf, as the show animation will do it.
- SelectedTabToolbarSizeChanged(false);
-}
-
-bool BrowserView::IsDownloadShelfVisible() const {
- return download_shelf_.get() && download_shelf_->IsShowing();
-}
-
-DownloadShelf* BrowserView::GetDownloadShelf() {
- if (!download_shelf_.get()) {
- download_shelf_.reset(new DownloadShelfView(browser_.get(), this));
- download_shelf_->set_parent_owned(false);
- }
- return download_shelf_.get();
-}
-
-void BrowserView::ShowReportBugDialog() {
- browser::ShowHtmlBugReportView(GetWindow(), browser_.get());
-}
-
-void BrowserView::ShowClearBrowsingDataDialog() {
- browser::ShowClearBrowsingDataView(GetWindow()->GetNativeWindow(),
- browser_->profile());
-}
-
-void BrowserView::ShowImportDialog() {
- browser::ShowImporterView(GetWidget(), browser_->profile());
-}
-
-void BrowserView::ShowSearchEnginesDialog() {
- browser::ShowKeywordEditorView(browser_->profile());
-}
-
-void BrowserView::ShowPasswordManager() {
- browser::ShowPasswordsExceptionsWindowView(browser_->profile());
-}
-
-void BrowserView::ShowRepostFormWarningDialog(TabContents* tab_contents) {
- browser::ShowRepostFormWarningDialog(GetNativeHandle(), tab_contents);
-}
-
-void BrowserView::ShowContentSettingsWindow(ContentSettingsType content_type,
- Profile* profile) {
- browser::ShowContentSettingsWindow(GetNativeHandle(), content_type, profile);
-}
-
-void BrowserView::ShowCollectedCookiesDialog(TabContents* tab_contents) {
- browser::ShowCollectedCookiesDialog(GetNativeHandle(), tab_contents);
-}
-
-void BrowserView::ShowProfileErrorDialog(int message_id) {
-#if defined(OS_WIN)
- std::wstring title = l10n_util::GetString(IDS_PRODUCT_NAME);
- std::wstring message = l10n_util::GetString(message_id);
- win_util::MessageBox(GetNativeHandle(), message, title,
- MB_OK | MB_ICONWARNING | MB_TOPMOST);
-#elif defined(OS_LINUX)
- std::string title = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
- std::string message = l10n_util::GetStringUTF8(message_id);
- GtkWidget* dialog = gtk_message_dialog_new(GetNativeHandle(),
- static_cast<GtkDialogFlags>(0), GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
- "%s", message.c_str());
- gtk_window_set_title(GTK_WINDOW(dialog), title.c_str());
- g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
- gtk_widget_show_all(dialog);
-#else
- NOTIMPLEMENTED();
-#endif
-}
-
-void BrowserView::ShowThemeInstallBubble() {
- TabContents* tab_contents = browser_->GetSelectedTabContents();
- if (!tab_contents)
- return;
- ThemeInstallBubbleView::Show(tab_contents);
-}
-
-void BrowserView::ConfirmBrowserCloseWithPendingDownloads() {
- DownloadInProgressConfirmDialogDelegate* delegate =
- new DownloadInProgressConfirmDialogDelegate(browser_.get());
- browser::CreateViewsWindow(GetNativeHandle(), gfx::Rect(),
- delegate)->Show();
-}
-
-void BrowserView::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
- gfx::NativeWindow parent_window) {
- // Default to using our window as the parent if the argument is not specified.
- gfx::NativeWindow parent = parent_window ? parent_window
- : GetNativeHandle();
-#if defined(OS_CHROMEOS)
- parent = GetNormalBrowserWindowForBrowser(browser(), NULL);
-#endif // defined(OS_CHROMEOS)
-
- browser::ShowHtmlDialogView(parent, browser_.get()->profile(), delegate);
-}
-
-void BrowserView::ShowCreateShortcutsDialog(TabContents* tab_contents) {
- browser::ShowCreateShortcutsDialog(GetNativeHandle(), tab_contents);
-}
-
-void BrowserView::ContinueDraggingDetachedTab(const gfx::Rect& tab_bounds) {
- tabstrip_->SetDraggedTabBounds(0, tab_bounds);
- frame_->ContinueDraggingDetachedTab();
-}
-
-void BrowserView::UserChangedTheme() {
- frame_->GetWindow()->FrameTypeChanged();
-}
-
-int BrowserView::GetExtraRenderViewHeight() const {
- // Currently this is only used on linux.
- return 0;
-}
-
-void BrowserView::TabContentsFocused(TabContents* tab_contents) {
- contents_container_->TabContentsFocused(tab_contents);
-}
-
-void BrowserView::ShowPageInfo(Profile* profile,
- const GURL& url,
- const NavigationEntry::SSLStatus& ssl,
- bool show_history) {
- gfx::NativeWindow parent = GetWindow()->GetNativeWindow();
-
-#if defined(OS_CHROMEOS)
- parent = GetNormalBrowserWindowForBrowser(browser(), profile);
-#endif // defined(OS_CHROMEOS)
-
- browser::ShowPageInfoBubble(parent, profile, url, ssl, show_history);
-}
-
-void BrowserView::ShowAppMenu() {
- toolbar_->app_menu()->Activate();
-}
-
-bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
- bool* is_keyboard_shortcut) {
- if (event.type != WebKit::WebInputEvent::RawKeyDown)
- return false;
-
-#if defined(OS_WIN)
- // As Alt+F4 is the close-app keyboard shortcut, it needs processing
- // immediately.
- if (event.windowsKeyCode == app::VKEY_F4 &&
- event.modifiers == NativeWebKeyboardEvent::AltKey) {
- DefWindowProc(event.os_event.hwnd, event.os_event.message,
- event.os_event.wParam, event.os_event.lParam);
- return true;
- }
-#endif
-
- views::FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
-
-#if defined(OS_LINUX)
- // Views and WebKit use different tables for GdkEventKey -> views::KeyEvent
- // conversion. We need to use View's conversion table here to keep consistent
- // behavior with views::FocusManager::OnKeyEvent() method.
- // TODO(suzhe): We need to check if Windows code also has this issue, and
- // it'll be best if we can unify these conversion tables.
- // See http://crbug.com/54315
- views::KeyEvent views_event(event.os_event);
- views::Accelerator accelerator(views_event.GetKeyCode(),
- views_event.IsShiftDown(),
- views_event.IsControlDown(),
- views_event.IsAltDown());
-#else
- views::Accelerator accelerator(
- static_cast<app::KeyboardCode>(event.windowsKeyCode),
- (event.modifiers & NativeWebKeyboardEvent::ShiftKey) ==
- NativeWebKeyboardEvent::ShiftKey,
- (event.modifiers & NativeWebKeyboardEvent::ControlKey) ==
- NativeWebKeyboardEvent::ControlKey,
- (event.modifiers & NativeWebKeyboardEvent::AltKey) ==
- NativeWebKeyboardEvent::AltKey);
-#endif
-
- // We first find out the browser command associated to the |event|.
- // Then if the command is a reserved one, and should be processed
- // immediately according to the |event|, the command will be executed
- // immediately. Otherwise we just set |*is_keyboard_shortcut| properly and
- // return false.
-
- // This piece of code is based on the fact that accelerators registered
- // into the |focus_manager| may only trigger a browser command execution.
- //
- // Here we need to retrieve the command id (if any) associated to the
- // keyboard event. Instead of looking up the command id in the
- // |accelerator_table_| by ourselves, we block the command execution of
- // the |browser_| object then send the keyboard event to the
- // |focus_manager| as if we are activating an accelerator key.
- // Then we can retrieve the command id from the |browser_| object.
- browser_->SetBlockCommandExecution(true);
- focus_manager->ProcessAccelerator(accelerator);
- int id = browser_->GetLastBlockedCommand(NULL);
- browser_->SetBlockCommandExecution(false);
-
- if (id == -1)
- return false;
-
- if (browser_->IsReservedCommand(id)) {
- // TODO(suzhe): For Linux, should we send things like Ctrl+w, Ctrl+n
- // to the renderer first, just like what
- // BrowserWindowGtk::HandleKeyboardEvent() does?
- // Executing the command may cause |this| object to be destroyed.
- browser_->ExecuteCommand(id);
- return true;
- }
-
- DCHECK(is_keyboard_shortcut != NULL);
- *is_keyboard_shortcut = true;
-
- return false;
-}
-
-void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
-#if defined(OS_LINUX)
- views::Window* window = GetWidget()->GetWindow();
- if (window && event.os_event && !event.skip_in_browser)
- static_cast<views::WindowGtk*>(window)->HandleKeyboardEvent(event.os_event);
-#else
- unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
- GetFocusManager());
-#endif
-}
-
-// TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always
-// enabled in the page menu regardless of whether the command will do
-// anything. When someone selects the menu item, we just act as if they hit
-// the keyboard shortcut for the command by sending the associated key press
-// to windows. The real fix to this bug is to disable the commands when they
-// won't do anything. We'll need something like an overall clipboard command
-// manager to do that.
-#if !defined(OS_MACOSX)
-void BrowserView::Cut() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_X,
- true, false, false, false);
-}
-
-void BrowserView::Copy() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_C,
- true, false, false, false);
-}
-
-void BrowserView::Paste() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V,
- true, false, false, false);
-}
-#else
-// Mac versions. Not tested by antyhing yet;
-// don't assume written == works.
-void BrowserView::Cut() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_X,
- false, false, false, true);
-}
-
-void BrowserView::Copy() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_C,
- false, false, false, true);
-}
-
-void BrowserView::Paste() {
- ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V,
- false, false, false, true);
-}
-#endif
-
-void BrowserView::ToggleTabStripMode() {
- InitTabStrip(browser_->tabstrip_model());
- frame_->TabStripDisplayModeChanged();
-}
-
-void BrowserView::ShowInstant(TabContents* preview_contents) {
- if (!preview_container_)
- preview_container_ = new TabContentsContainer();
- contents_->SetPreview(preview_container_, preview_contents);
- preview_container_->ChangeTabContents(preview_contents);
-}
-
-void BrowserView::HideInstant() {
- if (!preview_container_)
- return;
-
- // The contents must be changed before SetPreview is invoked.
- preview_container_->ChangeTabContents(NULL);
- contents_->SetPreview(NULL, NULL);
- delete preview_container_;
- preview_container_ = NULL;
-}
-
-gfx::Rect BrowserView::GetInstantBounds() {
- return contents_->GetPreviewBounds();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, BrowserWindowTesting implementation:
-
-BookmarkBarView* BrowserView::GetBookmarkBarView() const {
- return bookmark_bar_view_.get();
-}
-
-LocationBarView* BrowserView::GetLocationBarView() const {
- return toolbar_->location_bar();
-}
-
-views::View* BrowserView::GetTabContentsContainerView() const {
- return contents_container_->GetFocusView();
-}
-
-views::View* BrowserView::GetSidebarContainerView() const {
- if (!sidebar_container_)
- return NULL;
- return sidebar_container_->GetFocusView();
-}
-
-ToolbarView* BrowserView::GetToolbarView() const {
- return toolbar_;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, NotificationObserver implementation:
-
-void BrowserView::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type.value) {
- case NotificationType::PREF_CHANGED:
- if (*Details<std::string>(details).ptr() == prefs::kShowBookmarkBar &&
- MaybeShowBookmarkBar(browser_->GetSelectedTabContents())) {
- Layout();
- }
- break;
-
- case NotificationType::SIDEBAR_CHANGED:
- if (Details<SidebarContainer>(details)->tab_contents() ==
- browser_->GetSelectedTabContents()) {
- UpdateSidebar();
- }
- break;
-
- default:
- NOTREACHED() << "Got a notification we didn't register for!";
- break;
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, TabStripModelObserver implementation:
-
-void BrowserView::TabDetachedAt(TabContents* contents, int index) {
- // We use index here rather than comparing |contents| because by this time
- // the model has already removed |contents| from its list, so
- // browser_->GetSelectedTabContents() will return NULL or something else.
- if (index == browser_->tabstrip_model()->selected_index()) {
- // We need to reset the current tab contents to NULL before it gets
- // freed. This is because the focus manager performs some operations
- // on the selected TabContents when it is removed.
- contents_container_->ChangeTabContents(NULL);
- infobar_container_->ChangeTabContents(NULL);
- UpdateSidebarForContents(NULL);
- UpdateDevToolsForContents(NULL);
- }
-}
-
-void BrowserView::TabDeselectedAt(TabContents* contents, int index) {
- // We do not store the focus when closing the tab to work-around bug 4633.
- // Some reports seem to show that the focus manager and/or focused view can
- // be garbage at that point, it is not clear why.
- if (!contents->is_being_destroyed())
- contents->view()->StoreFocus();
-}
-
-void BrowserView::TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index,
- bool user_gesture) {
- DCHECK(old_contents != new_contents);
-
- ProcessTabSelected(new_contents, true);
-}
-
-void BrowserView::TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index) {
- if (index != browser_->tabstrip_model()->selected_index())
- return;
-
- // Swap the 'active' and 'preview' and delete what was the active.
- contents_->MakePreviewContentsActiveContents();
- TabContentsContainer* old_container = contents_container_;
- contents_container_ = preview_container_;
- old_container->ChangeTabContents(NULL);
- delete old_container;
- preview_container_ = NULL;
-
- // Update the UI for what was the preview contents and is now active. Pass in
- // false to ProcessTabSelected as new_contents is already parented correctly.
- ProcessTabSelected(new_contents, false);
-}
-
-void BrowserView::TabStripEmpty() {
- // Make sure all optional UI is removed before we are destroyed, otherwise
- // there will be consequences (since our view hierarchy will still have
- // references to freed views).
- UpdateUIForContents(NULL);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, menus::SimpleMenuModel::Delegate implementation:
-
-bool BrowserView::IsCommandIdChecked(int command_id) const {
- // TODO(beng): encoding menu.
- // No items in our system menu are check-able.
- return false;
-}
-
-bool BrowserView::IsCommandIdEnabled(int command_id) const {
- return browser_->command_updater()->IsCommandEnabled(command_id);
-}
-
-bool BrowserView::GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator) {
- // Let's let the ToolbarView own the canonical implementation of this method.
- return toolbar_->GetAcceleratorForCommandId(command_id, accelerator);
-}
-
-bool BrowserView::IsLabelForCommandIdDynamic(int command_id) const {
- return command_id == IDC_RESTORE_TAB;
-}
-
-string16 BrowserView::GetLabelForCommandId(int command_id) const {
- DCHECK(command_id == IDC_RESTORE_TAB);
-
- int string_id = IDS_RESTORE_TAB;
- if (IsCommandIdEnabled(command_id)) {
- TabRestoreService* trs = browser_->profile()->GetTabRestoreService();
- if (trs && trs->entries().front()->type == TabRestoreService::WINDOW)
- string_id = IDS_RESTORE_WINDOW;
- }
- return l10n_util::GetStringUTF16(string_id);
-}
-
-void BrowserView::ExecuteCommand(int command_id) {
- browser_->ExecuteCommand(command_id);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, views::WindowDelegate implementation:
-
-bool BrowserView::CanResize() const {
- return true;
-}
-
-bool BrowserView::CanMaximize() const {
- return true;
-}
-
-bool BrowserView::IsModal() const {
- return false;
-}
-
-std::wstring BrowserView::GetWindowTitle() const {
- return UTF16ToWideHack(browser_->GetWindowTitleForCurrentTab());
-}
-
-std::wstring BrowserView::GetAccessibleWindowTitle() const {
- if (IsOffTheRecord()) {
- return l10n_util::GetStringF(
- IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT, GetWindowTitle());
- }
- return GetWindowTitle();
-}
-
-views::View* BrowserView::GetInitiallyFocusedView() {
- // We set the frame not focus on creation so this should never be called.
- NOTREACHED();
- return NULL;
-}
-
-bool BrowserView::ShouldShowWindowTitle() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
-}
-
-SkBitmap BrowserView::GetWindowAppIcon() {
- if (browser_->type() & Browser::TYPE_APP) {
- TabContents* contents = browser_->GetSelectedTabContents();
- if (contents && !contents->app_icon().isNull())
- return contents->app_icon();
- }
-
- return GetWindowIcon();
-}
-
-SkBitmap BrowserView::GetWindowIcon() {
- if (browser_->type() & Browser::TYPE_APP)
- return browser_->GetCurrentPageIcon();
- return SkBitmap();
-}
-
-bool BrowserView::ShouldShowWindowIcon() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
-}
-
-bool BrowserView::ExecuteWindowsCommand(int command_id) {
- // This function handles WM_SYSCOMMAND, WM_APPCOMMAND, and WM_COMMAND.
-
- // Translate WM_APPCOMMAND command ids into a command id that the browser
- // knows how to handle.
- int command_id_from_app_command = GetCommandIDForAppCommandID(command_id);
- if (command_id_from_app_command != -1)
- command_id = command_id_from_app_command;
-
- if (browser_->command_updater()->SupportsCommand(command_id)) {
- if (browser_->command_updater()->IsCommandEnabled(command_id))
- browser_->ExecuteCommand(command_id);
- return true;
- }
- return false;
-}
-
-std::wstring BrowserView::GetWindowName() const {
- return UTF8ToWide(browser_->GetWindowPlacementKey());
-}
-
-void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
- bool maximized) {
- // If IsFullscreen() is true, we've just changed into fullscreen mode, and
- // we're catching the going-into-fullscreen sizing and positioning calls,
- // which we want to ignore.
- if (!IsFullscreen() && browser_->ShouldSaveWindowPlacement()) {
- WindowDelegate::SaveWindowPlacement(bounds, maximized);
- browser_->SaveWindowPlacement(bounds, maximized);
- }
-}
-
-bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const {
- *bounds = browser_->GetSavedWindowBounds();
- if (browser_->type() & Browser::TYPE_POPUP) {
- // We are a popup window. The value passed in |bounds| represents two
- // pieces of information:
- // - the position of the window, in screen coordinates (outer position).
- // - the size of the content area (inner size).
- // We need to use these values to determine the appropriate size and
- // position of the resulting window.
- if (IsToolbarVisible()) {
- // If we're showing the toolbar, we need to adjust |*bounds| to include
- // its desired height, since the toolbar is considered part of the
- // window's client area as far as GetWindowBoundsForClientBounds is
- // concerned...
- bounds->set_height(
- bounds->height() + toolbar_->GetPreferredSize().height());
- }
-
- gfx::Rect window_rect = frame_->GetWindow()->GetNonClientView()->
- GetWindowBoundsForClientBounds(*bounds);
- window_rect.set_origin(bounds->origin());
-
- // When we are given x/y coordinates of 0 on a created popup window,
- // assume none were given by the window.open() command.
- if (window_rect.x() == 0 && window_rect.y() == 0) {
- gfx::Size size = window_rect.size();
- window_rect.set_origin(WindowSizer::GetDefaultPopupOrigin(size));
- }
-
- *bounds = window_rect;
- }
-
- // We return true because we can _always_ locate reasonable bounds using the
- // WindowSizer, and we don't want to trigger the Window's built-in "size to
- // default" handling because the browser window has no default preferred
- // size.
- return true;
-}
-
-bool BrowserView::GetSavedMaximizedState(bool* maximized) const {
- *maximized = browser_->GetSavedMaximizedState();
- return true;
-}
-
-views::View* BrowserView::GetContentsView() {
- return contents_container_;
-}
-
-views::ClientView* BrowserView::CreateClientView(views::Window* window) {
- set_window(window);
- return this;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, views::ClientView overrides:
-
-bool BrowserView::CanClose() const {
- // You cannot close a frame for which there is an active originating drag
- // session.
- if (tabstrip_->IsDragSessionActive())
- return false;
-
- // Give beforeunload handlers the chance to cancel the close before we hide
- // the window below.
- if (!browser_->ShouldCloseWindow())
- return false;
-
- if (!browser_->tabstrip_model()->empty()) {
- // Tab strip isn't empty. Hide the frame (so it appears to have closed
- // immediately) and close all the tabs, allowing the renderers to shut
- // down. When the tab strip is empty we'll be called back again.
- frame_->GetWindow()->HideWindow();
- browser_->OnWindowClosing();
- return false;
- }
-
- // Empty TabStripModel, it's now safe to allow the Window to be closed.
- NotificationService::current()->Notify(
- NotificationType::WINDOW_CLOSED,
- Source<gfx::NativeWindow>(frame_->GetWindow()->GetNativeWindow()),
- NotificationService::NoDetails());
- return true;
-}
-
-int BrowserView::NonClientHitTest(const gfx::Point& point) {
-#if defined(OS_WIN)
- // The following code is not in the LayoutManager because it's
- // independent of layout and also depends on the ResizeCorner which
- // is private.
- if (!frame_->GetWindow()->IsMaximized() &&
- !frame_->GetWindow()->IsFullscreen()) {
- CRect client_rect;
- ::GetClientRect(frame_->GetWindow()->GetNativeWindow(), &client_rect);
- gfx::Size resize_corner_size = ResizeCorner::GetSize();
- gfx::Rect resize_corner_rect(client_rect.right - resize_corner_size.width(),
- client_rect.bottom - resize_corner_size.height(),
- resize_corner_size.width(), resize_corner_size.height());
- bool rtl_dir = base::i18n::IsRTL();
- if (rtl_dir)
- resize_corner_rect.set_x(0);
- if (resize_corner_rect.Contains(point)) {
- if (rtl_dir)
- return HTBOTTOMLEFT;
- return HTBOTTOMRIGHT;
- }
- }
-#endif
-
- return GetBrowserViewLayout()->NonClientHitTest(point);
-}
-
-gfx::Size BrowserView::GetMinimumSize() {
- return GetBrowserViewLayout()->GetMinimumSize();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, protected
-
-void BrowserView::GetAccessiblePanes(
- std::vector<AccessiblePaneView*>* panes) {
- // This should be in the order of pane traversal of the panes using F6.
- // If one of these is invisible or has no focusable children, it will be
- // automatically skipped.
- panes->push_back(toolbar_);
- if (bookmark_bar_view_.get())
- panes->push_back(bookmark_bar_view_.get());
- if (infobar_container_)
- panes->push_back(infobar_container_);
- if (download_shelf_.get())
- panes->push_back(download_shelf_.get());
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, views::View overrides:
-
-std::string BrowserView::GetClassName() const {
- return kViewClassName;
-}
-
-void BrowserView::Layout() {
- if (ignore_layout_)
- return;
- views::View::Layout();
-
- // The status bubble position requires that all other layout finish first.
- LayoutStatusBubble();
-
-#if defined(OS_WIN)
- // Send the margins of the "user-perceived content area" of this
- // browser window so AeroPeekManager can render a background-tab image in
- // the area.
- // TODO(pkasting) correct content inset??
- if (aeropeek_manager_.get()) {
- gfx::Insets insets(GetFindBarBoundingBox().y() + 1,
- 0,
- 0,
- 0);
- aeropeek_manager_->SetContentInsets(insets);
- }
-#endif
-}
-
-void BrowserView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && child == this && GetWidget() && !initialized_) {
- Init();
- initialized_ = true;
- }
-}
-
-void BrowserView::ChildPreferredSizeChanged(View* child) {
- Layout();
-}
-
-AccessibilityTypes::Role BrowserView::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_CLIENT;
-}
-
-void BrowserView::InfoBarSizeChanged(bool is_animating) {
- SelectedTabToolbarSizeChanged(is_animating);
-}
-
-views::LayoutManager* BrowserView::CreateLayoutManager() const {
- return new BrowserViewLayout;
-}
-
-void BrowserView::InitTabStrip(TabStripModel* model) {
- // Throw away the existing tabstrip if we're switching display modes.
- if (tabstrip_) {
- tabstrip_->GetParent()->RemoveChildView(tabstrip_);
- delete tabstrip_;
- }
-
- BrowserTabStripController* tabstrip_controller =
- new BrowserTabStripController(browser_.get(), model);
-
- if (UseVerticalTabs())
- tabstrip_ = new SideTabStrip(tabstrip_controller);
- else
- tabstrip_ = new TabStrip(tabstrip_controller);
-
- tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP));
- AddChildView(tabstrip_);
-
- tabstrip_controller->InitFromModel(tabstrip_);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView, private:
-
-void BrowserView::Init() {
- accessible_view_helper_.reset(new AccessibleViewHelper(
- this, browser_->profile()));
-
- SetLayoutManager(CreateLayoutManager());
- // Stow a pointer to this object onto the window handle so that we can get
- // at it later when all we have is a native view.
-#if defined(OS_WIN)
- GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this);
-#else
- g_object_set_data(G_OBJECT(GetWidget()->GetNativeView()),
- kBrowserViewKey, this);
-#endif
-
- // Start a hung plugin window detector for this browser object (as long as
- // hang detection is not disabled).
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableHangMonitor)) {
- InitHangMonitor();
- }
-
- LoadAccelerators();
- SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME));
-
- InitTabStrip(browser_->tabstrip_model());
-
- toolbar_ = new ToolbarView(browser_.get());
- AddChildView(toolbar_);
- toolbar_->Init(browser_->profile());
- toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR));
-
- infobar_container_ = new InfoBarContainer(this);
- AddChildView(infobar_container_);
-
- contents_container_ = new TabContentsContainer;
- contents_ = new ContentsContainer(this, contents_container_);
-
- SkColor bg_color = GetWidget()->GetThemeProvider()->
- GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
-
- bool sidebar_allowed = SidebarManager::IsSidebarAllowed();
- if (sidebar_allowed) {
- sidebar_container_ = new TabContentsContainer;
- sidebar_container_->SetID(VIEW_ID_SIDE_BAR_CONTAINER);
- sidebar_container_->SetVisible(false);
-
- sidebar_split_ = new views::SingleSplitView(
- contents_,
- sidebar_container_,
- views::SingleSplitView::HORIZONTAL_SPLIT);
- sidebar_split_->SetID(VIEW_ID_SIDE_BAR_SPLIT);
- sidebar_split_->
- SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_SIDE_BAR));
- sidebar_split_->set_background(
- views::Background::CreateSolidBackground(bg_color));
- }
-
- devtools_container_ = new TabContentsContainer;
- devtools_container_->SetID(VIEW_ID_DEV_TOOLS_DOCKED);
- devtools_container_->SetVisible(false);
-
- views::View* contents_view = contents_;
- if (sidebar_allowed)
- contents_view = sidebar_split_;
-
- contents_split_ = new views::SingleSplitView(
- contents_view,
- devtools_container_,
- views::SingleSplitView::VERTICAL_SPLIT);
- contents_split_->SetID(VIEW_ID_CONTENTS_SPLIT);
- contents_split_->
- SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_WEB_CONTENTS));
- contents_split_->set_background(
- views::Background::CreateSolidBackground(bg_color));
- AddChildView(contents_split_);
- set_contents_view(contents_split_);
-
- status_bubble_.reset(new StatusBubbleViews(contents_));
-
-#if defined(OS_WIN)
- InitSystemMenu();
-
- // Create a custom JumpList and add it to an observer of TabRestoreService
- // so we can update the custom JumpList when a tab is added or removed.
- if (JumpList::Enabled()) {
- jumplist_.reset(new JumpList);
- jumplist_->AddObserver(browser_->profile());
- }
-
- if (AeroPeekManager::Enabled()) {
- aeropeek_manager_.reset(new AeroPeekManager(
- frame_->GetWindow()->GetNativeWindow()));
- browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get());
- }
-#endif
-
- // We're now initialized and ready to process Layout requests.
- ignore_layout_ = false;
-}
-
-#if defined(OS_WIN)
-void BrowserView::InitSystemMenu() {
- system_menu_contents_.reset(new views::SystemMenuModel(this));
- // We add the menu items in reverse order so that insertion_index never needs
- // to change.
- if (IsBrowserTypeNormal())
- BuildSystemMenuForBrowserWindow();
- else
- BuildSystemMenuForAppOrPopupWindow(browser_->type() == Browser::TYPE_APP);
- system_menu_.reset(
- new views::NativeMenuWin(system_menu_contents_.get(),
- frame_->GetWindow()->GetNativeWindow()));
- system_menu_->Rebuild();
-}
-#endif
-
-BrowserViewLayout* BrowserView::GetBrowserViewLayout() const {
- return static_cast<BrowserViewLayout*>(GetLayoutManager());
-}
-
-void BrowserView::LayoutStatusBubble() {
- // In restored mode, the client area has a client edge between it and the
- // frame.
- int overlap = StatusBubbleViews::kShadowThickness +
- (IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness);
- int x = -overlap;
- if (UseVerticalTabs() && IsTabStripVisible())
- x += tabstrip_->bounds().right();
- int height = status_bubble_->GetPreferredSize().height();
- int contents_height = status_bubble_->base_view()->bounds().height();
- gfx::Point origin(-overlap, contents_height - height + overlap);
- status_bubble_->SetBounds(origin.x(), origin.y(), width() / 3, height);
-}
-
-bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) {
- views::View* new_bookmark_bar_view = NULL;
- if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)
- && contents) {
- if (!bookmark_bar_view_.get()) {
- bookmark_bar_view_.reset(new BookmarkBarView(contents->profile(),
- browser_.get()));
- bookmark_bar_view_->set_parent_owned(false);
- bookmark_bar_view_->set_background(
- new BookmarkExtensionBackground(this, bookmark_bar_view_.get(),
- browser_.get()));
- } else {
- bookmark_bar_view_->SetProfile(contents->profile());
- }
- bookmark_bar_view_->SetPageNavigator(contents);
- bookmark_bar_view_->
- SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BOOKMARKS));
- new_bookmark_bar_view = bookmark_bar_view_.get();
- }
- return UpdateChildViewAndLayout(new_bookmark_bar_view, &active_bookmark_bar_);
-}
-
-bool BrowserView::MaybeShowInfoBar(TabContents* contents) {
- // TODO(beng): Remove this function once the interface between
- // InfoBarContainer, DownloadShelfView and TabContents and this
- // view is sorted out.
- return true;
-}
-
-void BrowserView::UpdateSidebar() {
- UpdateSidebarForContents(GetSelectedTabContents());
- Layout();
-}
-
-void BrowserView::UpdateSidebarForContents(TabContents* tab_contents) {
- if (!sidebar_container_)
- return; // Happens when sidebar is not allowed.
- if (!SidebarManager::GetInstance())
- return; // Happens only in tests.
-
- TabContents* sidebar_contents = NULL;
- if (tab_contents) {
- SidebarContainer* client_host = SidebarManager::GetInstance()->
- GetActiveSidebarContainerFor(tab_contents);
- if (client_host)
- sidebar_contents = client_host->sidebar_contents();
- }
-
- bool visible = NULL != sidebar_contents &&
- browser_->SupportsWindowFeature(Browser::FEATURE_SIDEBAR);
-
- bool should_show = visible && !sidebar_container_->IsVisible();
- bool should_hide = !visible && sidebar_container_->IsVisible();
-
- // Update sidebar content.
- TabContents* old_contents = sidebar_container_->tab_contents();
- sidebar_container_->ChangeTabContents(sidebar_contents);
- SidebarManager::GetInstance()->
- NotifyStateChanges(old_contents, sidebar_contents);
-
- // Update sidebar UI width.
- if (should_show) {
- // Restore split offset.
- int sidebar_width = g_browser_process->local_state()->GetInteger(
- prefs::kExtensionSidebarWidth);
- if (sidebar_width < 0) {
- // Initial load, set to default value.
- sidebar_width = sidebar_split_->width() / 7;
- }
- // Make sure user can see both panes.
- int min_sidebar_width = sidebar_split_->GetMinimumSize().width();
- sidebar_width = std::min(sidebar_split_->width() - min_sidebar_width,
- std::max(min_sidebar_width, sidebar_width));
-
- sidebar_split_->set_divider_offset(
- sidebar_split_->width() - sidebar_width);
-
- sidebar_container_->SetVisible(true);
- sidebar_split_->Layout();
- } else if (should_hide) {
- // Store split offset when hiding sidebar only.
- g_browser_process->local_state()->SetInteger(
- prefs::kExtensionSidebarWidth,
- sidebar_split_->width() - sidebar_split_->divider_offset());
-
- sidebar_container_->SetVisible(false);
- sidebar_split_->Layout();
- }
-}
-
-void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) {
- TabContents* devtools_contents =
- DevToolsWindow::GetDevToolsContents(tab_contents);
-
- bool should_show = devtools_contents && !devtools_container_->IsVisible();
- bool should_hide = !devtools_contents && devtools_container_->IsVisible();
-
- devtools_container_->ChangeTabContents(devtools_contents);
-
- if (should_show) {
- if (!devtools_focus_tracker_.get()) {
- // Install devtools focus tracker when dev tools window is shown for the
- // first time.
- devtools_focus_tracker_.reset(
- new views::ExternalFocusTracker(devtools_container_,
- GetFocusManager()));
- }
-
- // Restore split offset.
- int split_offset = g_browser_process->local_state()->GetInteger(
- prefs::kDevToolsSplitLocation);
- if (split_offset == -1) {
- // Initial load, set to default value.
- split_offset = 2 * contents_split_->height() / 3;
- }
- // Make sure user can see both panes.
- int min_split_size = contents_split_->height() / 10;
- split_offset = std::min(contents_split_->height() - min_split_size,
- std::max(min_split_size, split_offset));
- contents_split_->set_divider_offset(split_offset);
-
- devtools_container_->SetVisible(true);
- contents_split_->Layout();
- } else if (should_hide) {
- // Store split offset when hiding devtools window only.
- g_browser_process->local_state()->SetInteger(
- prefs::kDevToolsSplitLocation, contents_split_->divider_offset());
-
- // Restore focus to the last focused view when hiding devtools window.
- devtools_focus_tracker_->FocusLastFocusedExternalView();
-
- devtools_container_->SetVisible(false);
- contents_split_->Layout();
- }
-}
-
-void BrowserView::UpdateUIForContents(TabContents* contents) {
- bool needs_layout = MaybeShowBookmarkBar(contents);
- needs_layout |= MaybeShowInfoBar(contents);
- if (needs_layout)
- Layout();
-}
-
-bool BrowserView::UpdateChildViewAndLayout(views::View* new_view,
- views::View** old_view) {
- DCHECK(old_view);
- if (*old_view == new_view) {
- // The views haven't changed, if the views pref changed schedule a layout.
- if (new_view) {
- if (new_view->GetPreferredSize().height() != new_view->height())
- return true;
- }
- return false;
- }
-
- // The views differ, and one may be null (but not both). Remove the old
- // view (if it non-null), and add the new one (if it is non-null). If the
- // height has changed, schedule a layout, otherwise reuse the existing
- // bounds to avoid scheduling a layout.
-
- int current_height = 0;
- if (*old_view) {
- current_height = (*old_view)->height();
- RemoveChildView(*old_view);
- }
-
- int new_height = 0;
- if (new_view) {
- new_height = new_view->GetPreferredSize().height();
- AddChildView(new_view);
- }
- bool changed = false;
- if (new_height != current_height) {
- changed = true;
- } else if (new_view && *old_view) {
- // The view changed, but the new view wants the same size, give it the
- // bounds of the last view and have it repaint.
- new_view->SetBounds((*old_view)->bounds());
- new_view->SchedulePaint();
- } else if (new_view) {
- DCHECK_EQ(0, new_height);
- // The heights are the same, but the old view is null. This only happens
- // when the height is zero. Zero out the bounds.
- new_view->SetBounds(0, 0, 0, 0);
- }
- *old_view = new_view;
- return changed;
-}
-
-void BrowserView::ProcessFullscreen(bool fullscreen) {
- // Reduce jankiness during the following position changes by:
- // * Hiding the window until it's in the final position
- // * Ignoring all intervening Layout() calls, which resize the webpage and
- // thus are slow and look ugly
- ignore_layout_ = true;
- LocationBarView* location_bar = toolbar_->location_bar();
-#if defined(OS_WIN)
- AutocompleteEditViewWin* edit_view =
- static_cast<AutocompleteEditViewWin*>(location_bar->location_entry());
-#endif
- if (!fullscreen) {
- // Hide the fullscreen bubble as soon as possible, since the mode toggle can
- // take enough time for the user to notice.
- fullscreen_bubble_.reset();
- } else {
- // Move focus out of the location bar if necessary.
- views::FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
- if (focus_manager->GetFocusedView() == location_bar)
- focus_manager->ClearFocus();
-
-#if defined(OS_WIN)
- // If we don't hide the edit and force it to not show until we come out of
- // fullscreen, then if the user was on the New Tab Page, the edit contents
- // will appear atop the web contents once we go into fullscreen mode. This
- // has something to do with how we move the main window while it's hidden;
- // if we don't hide the main window below, we don't get this problem.
- edit_view->set_force_hidden(true);
- ShowWindow(edit_view->m_hWnd, SW_HIDE);
-#endif
- }
-#if defined(OS_WIN)
- frame_->GetWindow()->PushForceHidden();
-#endif
-
- // Notify bookmark bar, so it can set itself to the appropriate drawing state.
- if (bookmark_bar_view_.get())
- bookmark_bar_view_->OnFullscreenToggled(fullscreen);
-
- // Toggle fullscreen mode.
-#if defined(OS_WIN)
- frame_->GetWindow()->SetFullscreen(fullscreen);
-#endif // No need to invoke SetFullscreen for linux as this code is executed
- // once we're already fullscreen on linux.
-
-#if defined(OS_LINUX)
- // Updating of commands for fullscreen mode is called from SetFullScreen on
- // Wndows (see just above), but for ChromeOS, this method (ProcessFullScreen)
- // is called after full screen has happened successfully (via GTK's
- // window-state-change event), so we have to update commands here.
- browser_->UpdateCommandsForFullscreenMode(fullscreen);
-#endif
-
- if (fullscreen) {
- bool is_kiosk =
- CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode);
- if (!is_kiosk) {
- fullscreen_bubble_.reset(new FullscreenExitBubble(GetWidget(),
- browser_.get()));
- }
- } else {
-#if defined(OS_WIN)
- // Show the edit again since we're no longer in fullscreen mode.
- edit_view->set_force_hidden(false);
- ShowWindow(edit_view->m_hWnd, SW_SHOW);
-#endif
- }
-
- // Undo our anti-jankiness hacks and force the window to relayout now that
- // it's in its final position.
- ignore_layout_ = false;
- Layout();
-#if defined(OS_WIN)
- frame_->GetWindow()->PopForceHidden();
-#endif
-}
-
-
-void BrowserView::LoadAccelerators() {
-#if defined(OS_WIN)
- HACCEL accelerator_table = AtlLoadAccelerators(IDR_MAINFRAME);
- DCHECK(accelerator_table);
-
- // We have to copy the table to access its contents.
- int count = CopyAcceleratorTable(accelerator_table, 0, 0);
- if (count == 0) {
- // Nothing to do in that case.
- return;
- }
-
- ACCEL* accelerators = static_cast<ACCEL*>(malloc(sizeof(ACCEL) * count));
- CopyAcceleratorTable(accelerator_table, accelerators, count);
-
- views::FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
-
- // Let's fill our own accelerator table.
- for (int i = 0; i < count; ++i) {
- bool alt_down = (accelerators[i].fVirt & FALT) == FALT;
- bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL;
- bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT;
- views::Accelerator accelerator(
- static_cast<app::KeyboardCode>(accelerators[i].key),
- shift_down, ctrl_down, alt_down);
- accelerator_table_[accelerator] = accelerators[i].cmd;
-
- // Also register with the focus manager.
- focus_manager->RegisterAccelerator(accelerator, this);
- }
-
- // We don't need the Windows accelerator table anymore.
- free(accelerators);
-#else
- views::FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
- // Let's fill our own accelerator table.
- for (size_t i = 0; i < browser::kAcceleratorMapLength; ++i) {
- views::Accelerator accelerator(browser::kAcceleratorMap[i].keycode,
- browser::kAcceleratorMap[i].shift_pressed,
- browser::kAcceleratorMap[i].ctrl_pressed,
- browser::kAcceleratorMap[i].alt_pressed);
- accelerator_table_[accelerator] = browser::kAcceleratorMap[i].command_id;
-
- // Also register with the focus manager.
- focus_manager->RegisterAccelerator(accelerator, this);
- }
-#endif
-}
-
-#if defined(OS_WIN)
-void BrowserView::BuildSystemMenuForBrowserWindow() {
- system_menu_contents_->AddSeparator();
- system_menu_contents_->AddItemWithStringId(IDC_TASK_MANAGER,
- IDS_TASK_MANAGER);
- system_menu_contents_->AddSeparator();
- system_menu_contents_->AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB);
- system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
- // If it's a regular browser window with tabs, we don't add any more items,
- // since it already has menus (Page, Chrome).
-}
-
-void BrowserView::BuildSystemMenuForAppOrPopupWindow(bool is_app) {
- if (is_app) {
- system_menu_contents_->AddSeparator();
- system_menu_contents_->AddItemWithStringId(IDC_TASK_MANAGER,
- IDS_TASK_MANAGER);
- }
- system_menu_contents_->AddSeparator();
- encoding_menu_contents_.reset(new EncodingMenuModel(browser_.get()));
- system_menu_contents_->AddSubMenuWithStringId(IDC_ENCODING_MENU,
- IDS_ENCODING_MENU,
- encoding_menu_contents_.get());
- zoom_menu_contents_.reset(new ZoomMenuModel(this));
- system_menu_contents_->AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_ZOOM_MENU,
- zoom_menu_contents_.get());
- system_menu_contents_->AddItemWithStringId(IDC_PRINT, IDS_PRINT);
- system_menu_contents_->AddItemWithStringId(IDC_FIND, IDS_FIND);
- system_menu_contents_->AddSeparator();
- system_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE);
- system_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY);
- system_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT);
- system_menu_contents_->AddSeparator();
- if (is_app) {
- system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB,
- IDS_APP_MENU_NEW_WEB_PAGE);
- } else {
- system_menu_contents_->AddItemWithStringId(IDC_SHOW_AS_TAB,
- IDS_SHOW_AS_TAB);
- }
- system_menu_contents_->AddItemWithStringId(IDC_COPY_URL,
- IDS_APP_MENU_COPY_URL);
- system_menu_contents_->AddSeparator();
- system_menu_contents_->AddItemWithStringId(IDC_RELOAD, IDS_APP_MENU_RELOAD);
- system_menu_contents_->AddItemWithStringId(IDC_FORWARD,
- IDS_CONTENT_CONTEXT_FORWARD);
- system_menu_contents_->AddItemWithStringId(IDC_BACK,
- IDS_CONTENT_CONTEXT_BACK);
-}
-#endif
-
-int BrowserView::GetCommandIDForAppCommandID(int app_command_id) const {
-#if defined(OS_WIN)
- switch (app_command_id) {
- // NOTE: The order here matches the APPCOMMAND declaration order in the
- // Windows headers.
- case APPCOMMAND_BROWSER_BACKWARD: return IDC_BACK;
- case APPCOMMAND_BROWSER_FORWARD: return IDC_FORWARD;
- case APPCOMMAND_BROWSER_REFRESH: return IDC_RELOAD;
- case APPCOMMAND_BROWSER_HOME: return IDC_HOME;
- case APPCOMMAND_BROWSER_STOP: return IDC_STOP;
- case APPCOMMAND_BROWSER_SEARCH: return IDC_FOCUS_SEARCH;
- case APPCOMMAND_HELP: return IDC_HELP_PAGE;
- case APPCOMMAND_NEW: return IDC_NEW_TAB;
- case APPCOMMAND_OPEN: return IDC_OPEN_FILE;
- case APPCOMMAND_CLOSE: return IDC_CLOSE_TAB;
- case APPCOMMAND_SAVE: return IDC_SAVE_PAGE;
- case APPCOMMAND_PRINT: return IDC_PRINT;
- case APPCOMMAND_COPY: return IDC_COPY;
- case APPCOMMAND_CUT: return IDC_CUT;
- case APPCOMMAND_PASTE: return IDC_PASTE;
-
- // TODO(pkasting): http://b/1113069 Handle these.
- case APPCOMMAND_UNDO:
- case APPCOMMAND_REDO:
- case APPCOMMAND_SPELL_CHECK:
- default: return -1;
- }
-#else
- // App commands are Windows-specific so there's nothing to do here.
- return -1;
-#endif
-}
-
-void BrowserView::LoadingAnimationCallback() {
- if (browser_->type() == Browser::TYPE_NORMAL) {
- // Loading animations are shown in the tab for tabbed windows. We check the
- // browser type instead of calling IsTabStripVisible() because the latter
- // will return false for fullscreen windows, but we still need to update
- // their animations (so that when they come out of fullscreen mode they'll
- // be correct).
- tabstrip_->UpdateLoadingAnimations();
- } else if (ShouldShowWindowIcon()) {
- // ... or in the window icon area for popups and app windows.
- TabContents* tab_contents = browser_->GetSelectedTabContents();
- // GetSelectedTabContents can return NULL for example under Purify when
- // the animations are running slowly and this function is called on a timer
- // through LoadingAnimationCallback.
- frame_->UpdateThrobber(tab_contents && tab_contents->is_loading());
- }
-}
-
-void BrowserView::InitHangMonitor() {
-#if defined(OS_WIN)
- PrefService* pref_service = g_browser_process->local_state();
- if (!pref_service)
- return;
-
- int plugin_message_response_timeout =
- pref_service->GetInteger(prefs::kPluginMessageResponseTimeout);
- int hung_plugin_detect_freq =
- pref_service->GetInteger(prefs::kHungPluginDetectFrequency);
- if ((hung_plugin_detect_freq > 0) &&
- hung_window_detector_.Initialize(GetWidget()->GetNativeView(),
- plugin_message_response_timeout)) {
- ticker_.set_tick_interval(hung_plugin_detect_freq);
- ticker_.RegisterTickHandler(&hung_window_detector_);
- ticker_.Start();
-
- pref_service->SetInteger(prefs::kPluginMessageResponseTimeout,
- plugin_message_response_timeout);
- pref_service->SetInteger(prefs::kHungPluginDetectFrequency,
- hung_plugin_detect_freq);
- }
-#endif
-}
-
-void BrowserView::ProcessTabSelected(TabContents* new_contents,
- bool change_tab_contents) {
- // Update various elements that are interested in knowing the current
- // TabContents.
-
- // When we toggle the NTP floating bookmarks bar and/or the info bar,
- // we don't want any TabContents to be attached, so that we
- // avoid an unnecessary resize and re-layout of a TabContents.
- if (change_tab_contents)
- contents_container_->ChangeTabContents(NULL);
- infobar_container_->ChangeTabContents(new_contents);
- UpdateUIForContents(new_contents);
- if (change_tab_contents)
- contents_container_->ChangeTabContents(new_contents);
- UpdateSidebarForContents(new_contents);
-
- UpdateDevToolsForContents(new_contents);
- // TODO(beng): This should be called automatically by ChangeTabContents, but I
- // am striving for parity now rather than cleanliness. This is
- // required to make features like Duplicate Tab, Undo Close Tab,
- // etc not result in sad tab.
- new_contents->DidBecomeSelected();
- if (BrowserList::GetLastActive() == browser_ &&
- !browser_->tabstrip_model()->closing_all() && GetWindow()->IsVisible()) {
- // We only restore focus if our window is visible, to avoid invoking blur
- // handlers when we are eventually shown.
- new_contents->view()->RestoreFocus();
- }
-
- // Update all the UI bits.
- UpdateTitleBar();
- UpdateToolbar(new_contents, true);
- UpdateUIForContents(new_contents);
-}
-
-#if !defined(OS_CHROMEOS)
-// static
-BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
- // Create the view and the frame. The frame will attach itself via the view
- // so we don't need to do anything with the pointer.
- BrowserView* view = new BrowserView(browser);
- BrowserFrame::Create(view, browser->profile());
-
- view->GetWindow()->GetNonClientView()->
- SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME));
-
- return view;
-}
-#endif
-
-// static
-FindBar* BrowserWindow::CreateFindBar(Browser* browser) {
- return browser::CreateFindBar(static_cast<BrowserView*>(browser->window()));
-}
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index d113525..4e90f82 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -2,653 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_VIEWS_FRAME_BROWSER_VIEW_H_
-#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_VIEW_H_
+#ifndef CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_VIEW_H_
+#define CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_VIEW_H_
#pragma once
-#include <map>
-#include <string>
-#include <vector>
+#include "chrome/browser/ui/views/frame/browser_view.h"
+// TODO(beng): remove this file once all includes have been updated.
-#include "app/menus/simple_menu_model.h"
-#include "base/scoped_ptr.h"
-#include "base/timer.h"
-#include "build/build_config.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/tabs/tab_strip_model_observer.h"
-#include "chrome/browser/views/frame/browser_bubble_host.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/infobars/infobar_container.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "chrome/browser/views/tabs/base_tab_strip.h"
-#include "chrome/browser/views/unhandled_keyboard_event_handler.h"
-#include "chrome/common/notification_registrar.h"
-#include "gfx/native_widget_types.h"
-#include "views/window/client_view.h"
-#include "views/window/window_delegate.h"
+#endif // CHROME_BROWSER_VIEWS_FRAME_POPUP_BROWSER_VIEW_H_
-#if defined(OS_WIN)
-#include "chrome/browser/hang_monitor/hung_plugin_action.h"
-#include "chrome/browser/hang_monitor/hung_window_detector.h"
-#include "views/controls/menu/native_menu_win.h"
-#endif
-
-// NOTE: For more information about the objects and files in this directory,
-// view: http://dev.chromium.org/developers/design-documents/browser-window
-
-class AccessiblePaneView;
-class AccessibleViewHelper;
-class BookmarkBarView;
-class Browser;
-class BrowserBubble;
-class BrowserViewLayout;
-class ContentsContainer;
-class DownloadShelfView;
-class EncodingMenuModel;
-class FullscreenExitBubble;
-class HtmlDialogUIDelegate;
-class InfoBarContainer;
-class LocationBarView;
-class SideTabStrip;
-class StatusBubbleViews;
-class TabContentsContainer;
-class TabStripModel;
-class ToolbarView;
-class ZoomMenuModel;
-
-#if defined(OS_WIN)
-class AeroPeekManager;
-class JumpList;
-#endif
-
-namespace views {
-class ExternalFocusTracker;
-class Menu;
-class SingleSplitView;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// BrowserView
-//
-// A ClientView subclass that provides the contents of a browser window,
-// including the TabStrip, toolbars, download shelves, the content area etc.
-//
-class BrowserView : public BrowserBubbleHost,
- public BrowserWindow,
- public BrowserWindowTesting,
- public NotificationObserver,
- public TabStripModelObserver,
- public menus::SimpleMenuModel::Delegate,
- public views::WindowDelegate,
- public views::ClientView,
- public InfoBarContainer::Delegate {
- public:
- // The browser view's class name.
- static const char kViewClassName[];
-
- // Explicitly sets how windows are shown. Use a value of -1 to give the
- // default behavior. This is used during testing and not generally useful
- // otherwise.
- static void SetShowState(int state);
-
- explicit BrowserView(Browser* browser);
- virtual ~BrowserView();
-
- void set_frame(BrowserFrame* frame) { frame_ = frame; }
- BrowserFrame* frame() const { return frame_; }
-
- // Returns a pointer to the BrowserView* interface implementation (an
- // instance of this object, typically) for a given native window, or NULL if
- // there is no such association.
- static BrowserView* GetBrowserViewForNativeWindow(gfx::NativeWindow window);
-
- // Returns a Browser instance of this view.
- Browser* browser() const { return browser_.get(); }
-
- // Returns the show flag that should be used to show the frame containing
- // this view.
- int GetShowState() const;
-
- // Called by the frame to notify the BrowserView that it was moved, and that
- // any dependent popup windows should be repositioned.
- void WindowMoved();
-
- // Called by the frame to notify the BrowserView that a move or resize was
- // initiated.
- void WindowMoveOrResizeStarted();
-
- // Returns the apparent bounds of the toolbar, in BrowserView coordinates.
- // These differ from |toolbar_.bounds()| in that they match where the toolbar
- // background image is drawn -- slightly outside the "true" bounds
- // horizontally, and, when using vertical tabs, behind the tab column.
- gfx::Rect GetToolbarBounds() const;
-
- // Returns the bounds of the content area, in the coordinates of the
- // BrowserView's parent.
- gfx::Rect GetClientAreaBounds() const;
-
- // Returns the constraining bounding box that should be used to lay out the
- // FindBar within. This is _not_ the size of the find bar, just the bounding
- // box it should be laid out within. The coordinate system of the returned
- // rect is in the coordinate system of the frame, since the FindBar is a child
- // window.
- gfx::Rect GetFindBarBoundingBox() const;
-
- // Returns the preferred height of the TabStrip. Used to position the OTR
- // avatar icon.
- int GetTabStripHeight() const;
-
- // Takes some view's origin (relative to this BrowserView) and offsets it such
- // that it can be used as the source origin for seamlessly tiling the toolbar
- // background image over that view.
- gfx::Point OffsetPointForToolbarBackgroundImage(
- const gfx::Point& point) const;
-
- // Returns the width of the currently displayed sidebar or 0.
- int GetSidebarWidth() const;
-
- // Accessor for the TabStrip.
- BaseTabStrip* tabstrip() const { return tabstrip_; }
-
- // Accessor for the Toolbar.
- ToolbarView* toolbar() const { return toolbar_; }
-
- // Returns true if various window components are visible.
- bool IsTabStripVisible() const;
-
- // Returns true if the vertical tabstrip is in use.
- bool UseVerticalTabs() const;
-
- // Returns true if the profile associated with this Browser window is
- // off the record.
- bool IsOffTheRecord() const;
-
- // Returns true if the non-client view should render the Off-The-Record
- // avatar icon if the window is off the record.
- bool ShouldShowOffTheRecordAvatar() const;
-
- // Handle the specified |accelerator| being pressed.
- bool AcceleratorPressed(const views::Accelerator& accelerator);
-
- // Provides the containing frame with the accelerator for the specified
- // command id. This can be used to provide menu item shortcut hints etc.
- // Returns true if an accelerator was found for the specified |cmd_id|, false
- // otherwise.
- bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator);
-
- // Shows the next app-modal dialog box, if there is one to be shown, or moves
- // an existing showing one to the front. Returns true if one was shown or
- // activated, false if none was shown.
- bool ActivateAppModalDialog() const;
-
- // Returns the selected TabContents. Used by our NonClientView's
- // TabIconView::TabContentsProvider implementations.
- // TODO(beng): exposing this here is a bit bogus, since it's only used to
- // determine loading state. It'd be nicer if we could change this to be
- // bool IsSelectedTabLoading() const; or something like that. We could even
- // move it to a WindowDelegate subclass.
- TabContents* GetSelectedTabContents() const;
-
- // Retrieves the icon to use in the frame to indicate an OTR window.
- SkBitmap GetOTRAvatarIcon();
-
-#if defined(OS_WIN)
- // Called right before displaying the system menu to allow the BrowserView
- // to add or delete entries.
- void PrepareToRunSystemMenu(HMENU menu);
-#endif
-
- // Returns true if the Browser object associated with this BrowserView is a
- // normal-type window (i.e. a browser window, not an app or popup).
- bool IsBrowserTypeNormal() const {
- return browser_->type() == Browser::TYPE_NORMAL;
- }
-
- // Returns true if the Browser object associated with this BrowserView is a
- // app panel window.
- bool IsBrowserTypePanel() const {
- return browser_->type() == Browser::TYPE_APP_PANEL;
- }
-
- // Returns true if the Browser object associated with this BrowserView is a
- // popup window.
- bool IsBrowserTypePopup() const {
- return (browser_->type() & Browser::TYPE_POPUP) != 0;
- }
-
- // Register preferences specific to this view.
- static void RegisterBrowserViewPrefs(PrefService* prefs);
-
- // Returns true if the specified point(BrowserView coordinates) is in
- // in the window caption area of the browser window.
- bool IsPositionInWindowCaption(const gfx::Point& point);
-
- // Returns whether the fullscreen bubble is visible or not.
- bool IsFullscreenBubbleVisible() const;
-
- // Invoked from the frame when the full screen state changes. This is only
- // used on Linux.
- void FullScreenStateChanged();
-
- // Restores the focused view. This is also used to set the initial focus
- // when a new browser window is created.
- void RestoreFocus();
-
- // Called when the activation of the frame changes.
- virtual void ActivationChanged(bool activated);
-
- // Overridden from BrowserWindow:
- virtual void Show();
- virtual void SetBounds(const gfx::Rect& bounds);
- virtual void Close();
- virtual void Activate();
- virtual void Deactivate();
- virtual bool IsActive() const;
- virtual void FlashFrame();
- virtual gfx::NativeWindow GetNativeHandle();
- virtual BrowserWindowTesting* GetBrowserWindowTesting();
- virtual StatusBubble* GetStatusBubble();
- virtual void SelectedTabToolbarSizeChanged(bool is_animating);
- virtual void UpdateTitleBar();
- virtual void ShelfVisibilityChanged();
- virtual void UpdateDevTools();
- virtual void UpdateLoadingAnimations(bool should_animate);
- virtual void SetStarredState(bool is_starred);
- virtual gfx::Rect GetRestoredBounds() const;
- virtual bool IsMaximized() const;
- virtual void SetFullscreen(bool fullscreen);
- virtual bool IsFullscreen() const;
- virtual LocationBar* GetLocationBar() const;
- virtual void SetFocusToLocationBar(bool select_all);
- virtual void UpdateReloadStopState(bool is_loading, bool force);
- virtual void UpdateToolbar(TabContents* contents, bool should_restore_state);
- virtual void FocusToolbar();
- virtual void FocusAppMenu();
- virtual void FocusBookmarksToolbar();
- virtual void FocusChromeOSStatus() {}
- virtual void RotatePaneFocus(bool forwards);
- virtual void DestroyBrowser();
- virtual bool IsBookmarkBarVisible() const;
- virtual bool IsBookmarkBarAnimating() const;
- virtual bool IsToolbarVisible() const;
- virtual gfx::Rect GetRootWindowResizerRect() const;
- virtual void DisableInactiveFrame();
- virtual void ConfirmSetDefaultSearchProvider(
- TabContents* tab_contents,
- TemplateURL* template_url,
- TemplateURLModel* template_url_model);
- virtual void ConfirmAddSearchProvider(const TemplateURL* template_url,
- Profile* profile);
- virtual void ToggleBookmarkBar();
- virtual views::Window* ShowAboutChromeDialog();
- virtual void ShowUpdateChromeDialog();
- virtual void ShowTaskManager();
- virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
- virtual void SetDownloadShelfVisible(bool visible);
- virtual bool IsDownloadShelfVisible() const;
- virtual DownloadShelf* GetDownloadShelf();
- virtual void ShowReportBugDialog();
- virtual void ShowClearBrowsingDataDialog();
- virtual void ShowImportDialog();
- virtual void ShowSearchEnginesDialog();
- virtual void ShowPasswordManager();
- virtual void ShowRepostFormWarningDialog(TabContents* tab_contents);
- virtual void ShowContentSettingsWindow(ContentSettingsType content_type,
- Profile* profile);
- virtual void ShowCollectedCookiesDialog(TabContents* tab_contents);
- virtual void ShowProfileErrorDialog(int message_id);
- virtual void ShowThemeInstallBubble();
- virtual void ConfirmBrowserCloseWithPendingDownloads();
- virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
- gfx::NativeWindow parent_window);
- virtual void ContinueDraggingDetachedTab(const gfx::Rect& tab_bounds);
- virtual void UserChangedTheme();
- virtual int GetExtraRenderViewHeight() const;
- virtual void TabContentsFocused(TabContents* source);
- virtual void ShowPageInfo(Profile* profile,
- const GURL& url,
- const NavigationEntry::SSLStatus& ssl,
- bool show_history);
- virtual void ShowAppMenu();
- virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
- bool* is_keyboard_shortcut);
- virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
- virtual void ShowCreateShortcutsDialog(TabContents* tab_contents);
- virtual void Cut();
- virtual void Copy();
- virtual void Paste();
- virtual void ToggleTabStripMode();
- virtual void ShowInstant(TabContents* preview_contents);
- virtual void HideInstant();
- virtual gfx::Rect GetInstantBounds();
-
- // Overridden from BrowserWindowTesting:
- virtual BookmarkBarView* GetBookmarkBarView() const;
- virtual LocationBarView* GetLocationBarView() const;
- virtual views::View* GetTabContentsContainerView() const;
- virtual views::View* GetSidebarContainerView() const;
- virtual ToolbarView* GetToolbarView() const;
-
- // Overridden from NotificationObserver:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Overridden from TabStripModelObserver:
- virtual void TabDetachedAt(TabContents* contents, int index);
- virtual void TabDeselectedAt(TabContents* contents, int index);
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index,
- bool user_gesture);
- virtual void TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index);
- virtual void TabStripEmpty();
-
- // Overridden from menus::SimpleMenuModel::Delegate:
- virtual bool IsCommandIdChecked(int command_id) const;
- virtual bool IsCommandIdEnabled(int command_id) const;
- virtual bool GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator);
- virtual bool IsLabelForCommandIdDynamic(int command_id) const;
- virtual string16 GetLabelForCommandId(int command_id) const;
- virtual void ExecuteCommand(int command_id);
-
- // Overridden from views::WindowDelegate:
- virtual bool CanResize() const;
- virtual bool CanMaximize() const;
- virtual bool IsModal() const;
- virtual std::wstring GetWindowTitle() const;
- virtual std::wstring GetAccessibleWindowTitle() const;
- virtual views::View* GetInitiallyFocusedView();
- virtual bool ShouldShowWindowTitle() const;
- virtual SkBitmap GetWindowAppIcon();
- virtual SkBitmap GetWindowIcon();
- virtual bool ShouldShowWindowIcon() const;
- virtual bool ExecuteWindowsCommand(int command_id);
- virtual std::wstring GetWindowName() const;
- virtual void SaveWindowPlacement(const gfx::Rect& bounds,
- bool maximized);
- virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const;
- virtual bool GetSavedMaximizedState(bool* maximized) const;
- virtual views::View* GetContentsView();
- virtual views::ClientView* CreateClientView(views::Window* window);
-
- // Overridden from views::ClientView:
- virtual bool CanClose() const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual gfx::Size GetMinimumSize();
-
- // InfoBarContainer::Delegate overrides
- virtual void InfoBarSizeChanged(bool is_animating);
-
- protected:
- // Appends to |toolbars| a pointer to each AccessiblePaneView that
- // can be traversed using F6, in the order they should be traversed.
- // Abstracted here so that it can be extended for Chrome OS.
- virtual void GetAccessiblePanes(
- std::vector<AccessiblePaneView*>* panes);
-
- // Save the current focused view to view storage
- void SaveFocusedView();
-
- int last_focused_view_storage_id() const {
- return last_focused_view_storage_id_;
- }
-
- // Overridden from views::View:
- virtual std::string GetClassName() const;
- virtual void Layout();
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
- virtual void ChildPreferredSizeChanged(View* child);
- virtual AccessibilityTypes::Role GetAccessibleRole();
-
- // Factory Methods.
- // Returns a new LayoutManager for this browser view. A subclass may
- // override to implemnet different layout pocily.
- virtual views::LayoutManager* CreateLayoutManager() const;
-
- // Initializes a new TabStrip for the browser view. This can be performed
- // multiple times over the life of the browser, and is run when the display
- // mode for the tabstrip changes from horizontal to vertical.
- virtual void InitTabStrip(TabStripModel* tab_strip_model);
-
- // Browser window related initializations.
- virtual void Init();
-
- private:
- friend class BrowserViewLayout;
-
-#if defined(OS_WIN)
- // Creates the system menu.
- void InitSystemMenu();
-#endif
-
- // Returns the BrowserViewLayout.
- BrowserViewLayout* GetBrowserViewLayout() const;
-
- // Layout the Status Bubble.
- void LayoutStatusBubble();
-
- // Prepare to show the Bookmark Bar for the specified TabContents. Returns
- // true if the Bookmark Bar can be shown (i.e. it's supported for this
- // Browser type) and there should be a subsequent re-layout to show it.
- // |contents| can be NULL.
- bool MaybeShowBookmarkBar(TabContents* contents);
-
- // Prepare to show an Info Bar for the specified TabContents. Returns true
- // if there is an Info Bar to show and one is supported for this Browser
- // type, and there should be a subsequent re-layout to show it.
- // |contents| can be NULL.
- bool MaybeShowInfoBar(TabContents* contents);
-
- // Updates sidebar UI according to the current tab and sidebar state.
- void UpdateSidebar();
- // Displays active sidebar linked to the |tab_contents| or hides sidebar UI,
- // if there's no such sidebar.
- void UpdateSidebarForContents(TabContents* tab_contents);
-
- // Updated devtools window for given contents.
- void UpdateDevToolsForContents(TabContents* tab_contents);
-
- // Updates various optional child Views, e.g. Bookmarks Bar, Info Bar or the
- // Download Shelf in response to a change notification from the specified
- // |contents|. |contents| can be NULL. In this case, all optional UI will be
- // removed.
- void UpdateUIForContents(TabContents* contents);
-
- // Updates an optional child View, e.g. Bookmarks Bar, Info Bar, Download
- // Shelf. If |*old_view| differs from new_view, the old_view is removed and
- // the new_view is added. This is intended to be used when swapping in/out
- // child views that are referenced via a field.
- // Returns true if anything was changed, and a re-Layout is now required.
- bool UpdateChildViewAndLayout(views::View* new_view, views::View** old_view);
-
- // Invoked to update the necessary things when our fullscreen state changes
- // to |fullscreen|. On Windows this is invoked immediately when we toggle the
- // full screen state. On Linux changing the fullscreen state is async, so we
- // ask the window to change it's fullscreen state, then when we get
- // notification that it succeeded this method is invoked.
- void ProcessFullscreen(bool fullscreen);
-
- // Copy the accelerator table from the app resources into something we can
- // use.
- void LoadAccelerators();
-
-#if defined(OS_WIN)
- // Builds the correct menu for when we have minimal chrome.
- void BuildSystemMenuForBrowserWindow();
- void BuildSystemMenuForAppOrPopupWindow(bool is_app);
-#endif
-
- // Retrieves the command id for the specified Windows app command.
- int GetCommandIDForAppCommandID(int app_command_id) const;
-
- // Callback for the loading animation(s) associated with this view.
- void LoadingAnimationCallback();
-
- // Initialize the hung plugin detector.
- void InitHangMonitor();
-
- // Invoked from TabSelectedAt or when instant is made active. Is
- // |change_tab_contents| is true, |new_contents| is added to the view
- // hierarchy, if |change_tab_contents| is false, it's assumed |new_contents|
- // has already been added to the view hierarchy.
- void ProcessTabSelected(TabContents* new_contents, bool change_tab_contents);
-
- // Last focused view that issued a tab traversal.
- int last_focused_view_storage_id_;
-
- // The BrowserFrame that hosts this view.
- BrowserFrame* frame_;
-
- // The Browser object we are associated with.
- scoped_ptr<Browser> browser_;
-
- // BrowserView layout (LTR one is pictured here).
- //
- // --------------------------------------------------------------------------
- // | | Tabs (1) |
- // | |--------------------------------------------------------------|
- // | | Navigation buttons, menus and the address bar (toolbar_) |
- // | |--------------------------------------------------------------|
- // | | All infobars (infobar_container_) * |
- // | |--------------------------------------------------------------|
- // | | Bookmarks (bookmark_bar_view_) * |
- // | |--------------------------------------------------------------|
- // | |Page content (contents_) || |
- // | |--------------------------------------|| Sidebar content |
- // | || contents_container_ and/or ||| (sidebar_container_) |
- // | || preview_container_ ||| |
- // | || |(3) |
- // | Tabs (2)|| ||| |
- // | || ||| |
- // | || ||| |
- // | || ||| |
- // | |--------------------------------------|| |
- // | |==(4)=========================================================|
- // | | |
- // | | |
- // | | Debugger (devtools_container_) |
- // | | |
- // | | |
- // | |--------------------------------------------------------------|
- // | | Active downloads (download_shelf_) |
- // --------------------------------------------------------------------------
- //
- // (1) - tabstrip_, default position
- // (2) - tabstrip_, position when side tabs are enabled
- // (3) - sidebar_split_
- // (4) - contents_split_
- //
- // * - The bookmark bar and info bar are swapped when on the new tab page.
- // Additionally contents_ is positioned on top of the bookmark bar when
- // the bookmark bar is detached. This is done to allow the
- // preview_container_ to appear over the bookmark bar.
-
- // Tool/Info bars that we are currently showing. Used for layout.
- // active_bookmark_bar_ is either NULL, if the bookmark bar isn't showing,
- // or is bookmark_bar_view_ if the bookmark bar is showing.
- views::View* active_bookmark_bar_;
-
- // The TabStrip.
- BaseTabStrip* tabstrip_;
-
- // The Toolbar containing the navigation buttons, menus and the address bar.
- ToolbarView* toolbar_;
-
- // The Bookmark Bar View for this window. Lazily created.
- scoped_ptr<BookmarkBarView> bookmark_bar_view_;
-
- // The download shelf view (view at the bottom of the page).
- scoped_ptr<DownloadShelfView> download_shelf_;
-
- // The InfoBarContainer that contains InfoBars for the current tab.
- InfoBarContainer* infobar_container_;
-
- // The view that contains sidebar for the current tab.
- TabContentsContainer* sidebar_container_;
-
- // Split view containing the contents container and sidebar container.
- views::SingleSplitView* sidebar_split_;
-
- // The view that contains the selected TabContents.
- TabContentsContainer* contents_container_;
-
- // The view that contains devtools window for the selected TabContents.
- TabContentsContainer* devtools_container_;
-
- // The view that contains instant's TabContents.
- TabContentsContainer* preview_container_;
-
- // The view managing both the contents_container_ and preview_container_.
- ContentsContainer* contents_;
-
- // Split view containing the contents container and devtools container.
- views::SingleSplitView* contents_split_;
-
- // Tracks and stores the last focused view which is not the
- // devtools_container_ or any of its children. Used to restore focus once
- // the devtools_container_ is hidden.
- scoped_ptr<views::ExternalFocusTracker> devtools_focus_tracker_;
-
- // The Status information bubble that appears at the bottom of the window.
- scoped_ptr<StatusBubbleViews> status_bubble_;
-
- // A mapping between accelerators and commands.
- std::map<views::Accelerator, int> accelerator_table_;
-
- // True if we have already been initialized.
- bool initialized_;
-
- // True if we should ignore requests to layout. This is set while toggling
- // fullscreen mode on and off to reduce jankiness.
- bool ignore_layout_;
-
- scoped_ptr<FullscreenExitBubble> fullscreen_bubble_;
-
-#if defined(OS_WIN)
- // The additional items we insert into the system menu.
- scoped_ptr<views::SystemMenuModel> system_menu_contents_;
- scoped_ptr<ZoomMenuModel> zoom_menu_contents_;
- scoped_ptr<EncodingMenuModel> encoding_menu_contents_;
- // The wrapped system menu itself.
- scoped_ptr<views::NativeMenuWin> system_menu_;
-
- // This object is used to perform periodic actions in a worker
- // thread. It is currently used to monitor hung plugin windows.
- WorkerThreadTicker ticker_;
-
- // This object is initialized with the frame window HWND. This
- // object is also passed as a tick handler with the ticker_ object.
- // It is used to periodically monitor for hung plugin windows
- HungWindowDetector hung_window_detector_;
-
- // This object is invoked by hung_window_detector_ when it detects a hung
- // plugin window.
- HungPluginAction hung_plugin_action_;
-
- // The custom JumpList for Windows 7.
- scoped_ptr<JumpList> jumplist_;
-
- // The custom AeroPeek manager for Windows 7.
- scoped_ptr<AeroPeekManager> aeropeek_manager_;
-#endif
-
- // The timer used to update frames for the Loading Animation.
- base::RepeatingTimer<BrowserView> loading_animation_timer_;
-
- UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
-
- scoped_ptr<AccessibleViewHelper> accessible_view_helper_;
-
- NotificationRegistrar registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserView);
-};
-
-#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_VIEW_H_
diff --git a/chrome/browser/views/frame/browser_view_layout.cc b/chrome/browser/views/frame/browser_view_layout.cc
deleted file mode 100644
index 5b7dc66..0000000
--- a/chrome/browser/views/frame/browser_view_layout.cc
+++ /dev/null
@@ -1,414 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/browser_view_layout.h"
-
-#include "chrome/browser/find_bar.h"
-#include "chrome/browser/find_bar_controller.h"
-#include "chrome/browser/sidebar/sidebar_manager.h"
-#include "chrome/browser/view_ids.h"
-#include "chrome/browser/views/bookmark_bar_view.h"
-#include "chrome/browser/views/download_shelf_view.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/frame/contents_container.h"
-#include "chrome/browser/views/tabs/side_tab_strip.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "chrome/browser/views/toolbar_view.h"
-#include "gfx/scrollbar_size.h"
-#include "views/window/window.h"
-
-#if defined(OS_LINUX)
-#include "views/window/hit_test.h"
-#endif
-
-namespace {
-
-// The visible height of the shadow above the tabs. Clicks in this area are
-// treated as clicks to the frame, rather than clicks to the tab.
-const int kTabShadowSize = 2;
-// The vertical overlap between the TabStrip and the Toolbar.
-const int kToolbarTabStripVerticalOverlap = 3;
-// An offset distance between certain toolbars and the toolbar that preceded
-// them in layout.
-const int kSeparationLineHeight = 1;
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-// BrowserViewLayout, public:
-
-BrowserViewLayout::BrowserViewLayout()
- : tabstrip_(NULL),
- toolbar_(NULL),
- contents_split_(NULL),
- contents_container_(NULL),
- infobar_container_(NULL),
- download_shelf_(NULL),
- active_bookmark_bar_(NULL),
- browser_view_(NULL),
- find_bar_y_(0) {
-}
-
-gfx::Size BrowserViewLayout::GetMinimumSize() {
- // TODO(noname): In theory the tabstrip width should probably be
- // (OTR + tabstrip + caption buttons) width.
- gfx::Size tabstrip_size(
- browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ?
- tabstrip_->GetMinimumSize() : gfx::Size());
- gfx::Size toolbar_size(
- (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
- browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ?
- toolbar_->GetMinimumSize() : gfx::Size());
- if (tabstrip_size.height() && toolbar_size.height())
- toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap);
- gfx::Size bookmark_bar_size;
- if (active_bookmark_bar_ &&
- browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) {
- bookmark_bar_size = active_bookmark_bar_->GetMinimumSize();
- bookmark_bar_size.Enlarge(0, -(kSeparationLineHeight +
- active_bookmark_bar_->GetToolbarOverlap(true)));
- }
- gfx::Size contents_size(contents_split_->GetMinimumSize());
-
- int min_height = tabstrip_size.height() + toolbar_size.height() +
- bookmark_bar_size.height() + contents_size.height();
- int widths[] = { tabstrip_size.width(), toolbar_size.width(),
- bookmark_bar_size.width(), contents_size.width() };
- int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]);
- return gfx::Size(min_width, min_height);
-}
-
-gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const {
- // This function returns the area the Find Bar can be laid out
- // within. This basically implies the "user-perceived content
- // area" of the browser window excluding the vertical
- // scrollbar. This is not quite so straightforward as positioning
- // based on the TabContentsContainer since the BookmarkBarView may
- // be visible but not persistent (in the New Tab case) and we
- // position the Find Bar over the top of it in that case since the
- // BookmarkBarView is not _visually_ connected to the Toolbar.
-
- // First determine the bounding box of the content area in Widget
- // coordinates.
- gfx::Rect bounding_box(contents_container_->bounds());
-
- gfx::Point topleft;
- views::View::ConvertPointToWidget(contents_container_, &topleft);
- bounding_box.set_origin(topleft);
-
- // Adjust the position and size of the bounding box by the find bar offset
- // calculated during the last Layout.
- int height_delta = find_bar_y_ - bounding_box.y();
- bounding_box.set_y(find_bar_y_);
- bounding_box.set_height(std::max(0, bounding_box.height() + height_delta));
-
- // Finally decrease the width of the bounding box by the width of
- // the vertical scroll bar.
- int scrollbar_width = gfx::scrollbar_size();
- bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width));
- if (base::i18n::IsRTL())
- bounding_box.set_x(bounding_box.x() + scrollbar_width);
-
- return bounding_box;
-}
-
-bool BrowserViewLayout::IsPositionInWindowCaption(
- const gfx::Point& point) {
- gfx::Point tabstrip_point(point);
- views::View::ConvertPointToView(browser_view_, tabstrip_, &tabstrip_point);
- return tabstrip_->IsPositionInWindowCaption(tabstrip_point);
-}
-
-int BrowserViewLayout::NonClientHitTest(
- const gfx::Point& point) {
- // Since the TabStrip only renders in some parts of the top of the window,
- // the un-obscured area is considered to be part of the non-client caption
- // area of the window. So we need to treat hit-tests in these regions as
- // hit-tests of the titlebar.
-
- views::View* parent = browser_view_->GetParent();
-
- gfx::Point point_in_browser_view_coords(point);
- views::View::ConvertPointToView(
- parent, browser_view_, &point_in_browser_view_coords);
-
- // Determine if the TabStrip exists and is capable of being clicked on. We
- // might be a popup window without a TabStrip.
- if (browser_view_->IsTabStripVisible()) {
- // See if the mouse pointer is within the bounds of the TabStrip.
- gfx::Point point_in_tabstrip_coords(point);
- views::View::ConvertPointToView(parent, tabstrip_,
- &point_in_tabstrip_coords);
- if (tabstrip_->HitTest(point_in_tabstrip_coords)) {
- if (tabstrip_->IsPositionInWindowCaption(point_in_tabstrip_coords))
- return HTCAPTION;
- return HTCLIENT;
- }
-
- // The top few pixels of the TabStrip are a drop-shadow - as we're pretty
- // starved of dragable area, let's give it to window dragging (this also
- // makes sense visually).
- if (!browser_view_->IsMaximized() &&
- (point_in_browser_view_coords.y() <
- (tabstrip_->y() + kTabShadowSize))) {
- // We return HTNOWHERE as this is a signal to our containing
- // NonClientView that it should figure out what the correct hit-test
- // code is given the mouse position...
- return HTNOWHERE;
- }
- }
-
- // If the point's y coordinate is below the top of the toolbar and otherwise
- // within the bounds of this view, the point is considered to be within the
- // client area.
- gfx::Rect bv_bounds = browser_view_->bounds();
- bv_bounds.Offset(0, toolbar_->y());
- bv_bounds.set_height(bv_bounds.height() - toolbar_->y());
- if (bv_bounds.Contains(point))
- return HTCLIENT;
-
- // If the point's y coordinate is above the top of the toolbar, but not in
- // the tabstrip (per previous checking in this function), then we consider it
- // in the window caption (e.g. the area to the right of the tabstrip
- // underneath the window controls). However, note that we DO NOT return
- // HTCAPTION here, because when the window is maximized the window controls
- // will fall into this space (since the BrowserView is sized to entire size
- // of the window at that point), and the HTCAPTION value will cause the
- // window controls not to work. So we return HTNOWHERE so that the caller
- // will hit-test the window controls before finally falling back to
- // HTCAPTION.
- bv_bounds = browser_view_->bounds();
- bv_bounds.set_height(toolbar_->y());
- if (bv_bounds.Contains(point))
- return HTNOWHERE;
-
- // If the point is somewhere else, delegate to the default implementation.
- return browser_view_->views::ClientView::NonClientHitTest(point);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// BrowserViewLayout, views::LayoutManager implementation:
-
-void BrowserViewLayout::Installed(views::View* host) {
- toolbar_ = NULL;
- contents_split_ = NULL;
- contents_container_ = NULL;
- infobar_container_ = NULL;
- download_shelf_ = NULL;
- active_bookmark_bar_ = NULL;
- tabstrip_ = NULL;
- browser_view_ = static_cast<BrowserView*>(host);
-}
-
-void BrowserViewLayout::Uninstalled(views::View* host) {}
-
-void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) {
- switch (view->GetID()) {
- case VIEW_ID_CONTENTS_SPLIT: {
- contents_split_ = view;
- // We're installed as the LayoutManager before BrowserView creates the
- // contents, so we have to set contents_container_ here rather than
- // Installed.
- contents_container_ = browser_view_->contents_;
- break;
- }
- case VIEW_ID_INFO_BAR_CONTAINER:
- infobar_container_ = view;
- break;
- case VIEW_ID_DOWNLOAD_SHELF:
- download_shelf_ = static_cast<DownloadShelfView*>(view);
- break;
- case VIEW_ID_BOOKMARK_BAR:
- active_bookmark_bar_ = static_cast<BookmarkBarView*>(view);
- break;
- case VIEW_ID_TOOLBAR:
- toolbar_ = static_cast<ToolbarView*>(view);
- break;
- case VIEW_ID_TAB_STRIP:
- tabstrip_ = static_cast<BaseTabStrip*>(view);
- break;
- }
-}
-
-void BrowserViewLayout::ViewRemoved(views::View* host, views::View* view) {
- switch (view->GetID()) {
- case VIEW_ID_BOOKMARK_BAR:
- active_bookmark_bar_ = NULL;
- break;
- }
-}
-
-void BrowserViewLayout::Layout(views::View* host) {
- vertical_layout_rect_ = browser_view_->GetLocalBounds(true);
- int top = LayoutTabStrip();
- if (browser_view_->IsTabStripVisible() && !browser_view_->UseVerticalTabs()) {
- tabstrip_->SetBackgroundOffset(gfx::Point(
- tabstrip_->MirroredX() + browser_view_->MirroredX(),
- browser_view_->frame()->GetHorizontalTabStripVerticalOffset(false)));
- }
- top = LayoutToolbar(top);
- top = LayoutBookmarkAndInfoBars(top);
- int bottom = LayoutDownloadShelf(browser_view_->height());
- int active_top_margin = GetTopMarginForActiveContent();
- top -= active_top_margin;
- contents_container_->SetActiveTopMargin(active_top_margin);
- LayoutTabContents(top, bottom);
- // This must be done _after_ we lay out the TabContents since this
- // code calls back into us to find the bounding box the find bar
- // must be laid out within, and that code depends on the
- // TabContentsContainer's bounds being up to date.
- if (browser()->HasFindBarController()) {
- browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary(
- gfx::Rect(), true);
- }
-}
-
-// Return the preferred size which is the size required to give each
-// children their respective preferred size.
-gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) {
- return gfx::Size();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// BrowserViewLayout, private:
-
-Browser* BrowserViewLayout::browser() {
- return browser_view_->browser();
-}
-
-const Browser* BrowserViewLayout::browser() const {
- return browser_view_->browser();
-}
-
-int BrowserViewLayout::LayoutTabStrip() {
- if (!browser_view_->IsTabStripVisible()) {
- tabstrip_->SetVisible(false);
- tabstrip_->SetBounds(0, 0, 0, 0);
- return 0;
- }
-
- gfx::Rect tabstrip_bounds(
- browser_view_->frame()->GetBoundsForTabStrip(tabstrip_));
- gfx::Point tabstrip_origin(tabstrip_bounds.origin());
- views::View::ConvertPointToView(browser_view_->GetParent(), browser_view_,
- &tabstrip_origin);
- tabstrip_bounds.set_origin(tabstrip_origin);
-
- if (browser_view_->UseVerticalTabs())
- vertical_layout_rect_.Inset(tabstrip_bounds.width(), 0, 0, 0);
-
- tabstrip_->SetVisible(true);
- tabstrip_->SetBounds(tabstrip_bounds);
- return browser_view_->UseVerticalTabs() ?
- tabstrip_bounds.y() : tabstrip_bounds.bottom();
-}
-
-int BrowserViewLayout::LayoutToolbar(int top) {
- int browser_view_width = vertical_layout_rect_.width();
- bool visible = browser_view_->IsToolbarVisible();
- toolbar_->location_bar()->SetFocusable(visible);
- int y = top;
- if (!browser_view_->UseVerticalTabs()) {
- y -= ((visible && browser_view_->IsTabStripVisible()) ?
- kToolbarTabStripVerticalOverlap : 0);
- }
- int height = visible ? toolbar_->GetPreferredSize().height() : 0;
- toolbar_->SetVisible(visible);
- toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height);
- return y + height;
-}
-
-int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) {
- find_bar_y_ = top + browser_view_->y() - 1;
- if (active_bookmark_bar_) {
- // If we're showing the Bookmark bar in detached style, then we
- // need to show any Info bar _above_ the Bookmark bar, since the
- // Bookmark bar is styled to look like it's part of the page.
- if (active_bookmark_bar_->IsDetached())
- return LayoutBookmarkBar(LayoutInfoBar(top));
- // Otherwise, Bookmark bar first, Info bar second.
- top = std::max(toolbar_->bounds().bottom(), LayoutBookmarkBar(top));
- }
- find_bar_y_ = top + browser_view_->y() - 1;
- return LayoutInfoBar(top);
-}
-
-int BrowserViewLayout::LayoutBookmarkBar(int top) {
- DCHECK(active_bookmark_bar_);
- int y = top;
- if (!browser_view_->IsBookmarkBarVisible()) {
- active_bookmark_bar_->SetVisible(false);
- active_bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0);
- return y;
- }
-
- active_bookmark_bar_->set_infobar_visible(InfobarVisible());
- int bookmark_bar_height = active_bookmark_bar_->GetPreferredSize().height();
- y -= kSeparationLineHeight + active_bookmark_bar_->GetToolbarOverlap(false);
- active_bookmark_bar_->SetVisible(true);
- active_bookmark_bar_->SetBounds(vertical_layout_rect_.x(), y,
- vertical_layout_rect_.width(),
- bookmark_bar_height);
- return y + bookmark_bar_height;
-}
-
-int BrowserViewLayout::LayoutInfoBar(int top) {
- bool visible = InfobarVisible();
- int height = visible ? infobar_container_->GetPreferredSize().height() : 0;
- infobar_container_->SetVisible(visible);
- infobar_container_->SetBounds(vertical_layout_rect_.x(), top,
- vertical_layout_rect_.width(), height);
- return top + height;
-}
-
-void BrowserViewLayout::LayoutTabContents(int top, int bottom) {
- contents_split_->SetBounds(vertical_layout_rect_.x(), top,
- vertical_layout_rect_.width(), bottom - top);
-}
-
-int BrowserViewLayout::GetTopMarginForActiveContent() {
- if (!active_bookmark_bar_ || !browser_view_->IsBookmarkBarVisible() ||
- !active_bookmark_bar_->IsDetached()) {
- return 0;
- }
-
- if (contents_split_->GetChildViewAt(1) &&
- contents_split_->GetChildViewAt(1)->IsVisible())
- return 0;
-
- if (SidebarManager::IsSidebarAllowed()) {
- views::View* sidebar_split = contents_split_->GetChildViewAt(0);
- if (sidebar_split->GetChildViewAt(1) &&
- sidebar_split->GetChildViewAt(1)->IsVisible())
- return 0;
- }
-
- // Adjust for separator.
- return active_bookmark_bar_->height() - kSeparationLineHeight;
-}
-
-int BrowserViewLayout::LayoutDownloadShelf(int bottom) {
- // Re-layout the shelf either if it is visible or if it's close animation
- // is currently running.
- if (browser_view_->IsDownloadShelfVisible() ||
- (download_shelf_ && download_shelf_->IsClosing())) {
- bool visible = browser()->SupportsWindowFeature(
- Browser::FEATURE_DOWNLOADSHELF);
- DCHECK(download_shelf_);
- int height = visible ? download_shelf_->GetPreferredSize().height() : 0;
- download_shelf_->SetVisible(visible);
- download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height,
- vertical_layout_rect_.width(), height);
- download_shelf_->Layout();
- bottom -= height;
- }
- return bottom;
-}
-
-bool BrowserViewLayout::InfobarVisible() const {
- // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
- return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
- (infobar_container_->GetPreferredSize().height() != 0);
-}
diff --git a/chrome/browser/views/frame/browser_view_layout.h b/chrome/browser/views/frame/browser_view_layout.h
index 42652ef..a96fa8e 100644
--- a/chrome/browser/views/frame/browser_view_layout.h
+++ b/chrome/browser/views/frame/browser_view_layout.h
@@ -6,107 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
#pragma once
-#include "views/layout_manager.h"
-
-class BaseTabStrip;
-class BookmarkBarView;
-class Browser;
-class BrowserView;
-class ContentsContainer;
-class DownloadShelfView;
-class ToolbarView;
-
-// The layout manager used in chrome browser.
-class BrowserViewLayout : public views::LayoutManager {
- public:
- BrowserViewLayout();
- virtual ~BrowserViewLayout() {}
-
- // Returns the minimum size of the browser view.
- virtual gfx::Size GetMinimumSize();
-
- // Returns the bounding box for the find bar.
- virtual gfx::Rect GetFindBarBoundingBox() const;
-
- // Returns true if the specified point(BrowserView coordinates) is in
- // in the window caption area of the browser window.
- virtual bool IsPositionInWindowCaption(const gfx::Point& point);
-
- // Tests to see if the specified |point| (in nonclient view's coordinates)
- // is within the views managed by the laymanager. Returns one of
- // HitTestCompat enum defined in views/window/hit_test.h.
- // See also ClientView::NonClientHitTest.
- virtual int NonClientHitTest(const gfx::Point& point);
-
- // views::LayoutManager overrides:
- virtual void Installed(views::View* host);
- virtual void Uninstalled(views::View* host);
- virtual void ViewAdded(views::View* host, views::View* view);
- virtual void ViewRemoved(views::View* host, views::View* view);
- virtual void Layout(views::View* host);
- virtual gfx::Size GetPreferredSize(views::View* host);
-
- protected:
- Browser* browser();
- const Browser* browser() const;
-
- // Layout the TabStrip, returns the coordinate of the bottom of the TabStrip,
- // for laying out subsequent controls.
- virtual int LayoutTabStrip();
-
- // Layout the following controls, starting at |top|, returns the coordinate
- // of the bottom of the control, for laying out the next control.
- virtual int LayoutToolbar(int top);
- int LayoutBookmarkAndInfoBars(int top);
- int LayoutBookmarkBar(int top);
- int LayoutInfoBar(int top);
-
- // Layout the TabContents container, between the coordinates |top| and
- // |bottom|.
- void LayoutTabContents(int top, int bottom);
-
- // Returns the top margin to adjust the contents_container_ by. This is used
- // to make the bookmark bar and contents_container_ overlap so that the
- // preview contents hides the bookmark bar.
- int GetTopMarginForActiveContent();
-
- // Layout the Download Shelf, returns the coordinate of the top of the
- // control, for laying out the previous control.
- int LayoutDownloadShelf(int bottom);
-
- // Returns true if an infobar is showing.
- bool InfobarVisible() const;
-
- // See description above vertical_layout_rect_ for details.
- void set_vertical_layout_rect(const gfx::Rect& bounds) {
- vertical_layout_rect_ = bounds;
- }
- const gfx::Rect& vertical_layout_rect() const {
- return vertical_layout_rect_;
- }
-
- // Child views that the layout manager manages.
- BaseTabStrip* tabstrip_;
- ToolbarView* toolbar_;
- views::View* contents_split_;
- ContentsContainer* contents_container_;
- views::View* infobar_container_;
- DownloadShelfView* download_shelf_;
- BookmarkBarView* active_bookmark_bar_;
-
- BrowserView* browser_view_;
-
- // The bounds within which the vertically-stacked contents of the BrowserView
- // should be laid out within. When the SideTabstrip is not visible, this is
- // just the local bounds of the BrowserView, otherwise it's the local bounds
- // of the BrowserView less the width of the SideTabstrip.
- gfx::Rect vertical_layout_rect_;
-
- // The distance the FindBar is from the top of the window, in pixels.
- int find_bar_y_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout);
-};
+#include "chrome/browser/ui/views/frame/browser_view_layout.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
diff --git a/chrome/browser/views/frame/contents_container.cc b/chrome/browser/views/frame/contents_container.cc
deleted file mode 100644
index fd80e3b..0000000
--- a/chrome/browser/views/frame/contents_container.cc
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/contents_container.h"
-
-#include "app/resource_bundle.h"
-#include "chrome/browser/location_bar.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "grit/theme_resources.h"
-#include "views/controls/image_view.h"
-#include "views/widget/root_view.h"
-
-#if defined(OS_WIN)
-#include "views/widget/widget_win.h"
-#elif defined(OS_LINUX)
-#include "chrome/browser/gtk/gtk_util.h"
-#include "views/window/window_gtk.h"
-#endif
-
-#if defined(OS_WIN)
-
-class ContentsContainer::TearWindow : public views::WidgetWin {
- public:
- explicit TearWindow(ContentsContainer* contents_container)
- : contents_container_(contents_container) {
- set_window_style(WS_POPUP | WS_CLIPCHILDREN);
- set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED);
- }
-
- virtual ~TearWindow() {
- // On windows it's possible for us to be deleted before the
- // ContentsContainer. If this happens make sure contents_container_ doesn't
- // attempt to delete us too.
- if (contents_container_)
- contents_container_->TearWindowDestroyed();
- }
-
- void set_contents_container(ContentsContainer* contents_container) {
- contents_container_ = contents_container;
- }
-
- virtual LRESULT OnMouseActivate(HWND window,
- UINT hit_test,
- UINT mouse_message) {
- // Don't activate the window when the user clicks it.
- contents_container_->browser_view_->GetLocationBar()->Revert();
- return MA_NOACTIVATE;
- }
-
- private:
- ContentsContainer* contents_container_;
-
- DISALLOW_COPY_AND_ASSIGN(TearWindow);
-};
-
-#endif
-
-ContentsContainer::ContentsContainer(BrowserView* browser_view,
- views::View* active)
- : browser_view_(browser_view),
- active_(active),
- preview_(NULL),
- preview_tab_contents_(NULL),
- tear_window_(NULL),
- active_top_margin_(0) {
- AddChildView(active_);
-}
-
-ContentsContainer::~ContentsContainer() {
- DeleteTearWindow();
-}
-
-void ContentsContainer::MakePreviewContentsActiveContents() {
- active_ = preview_;
- preview_ = NULL;
- DeleteTearWindow();
- Layout();
-}
-
-void ContentsContainer::SetPreview(views::View* preview,
- TabContents* preview_tab_contents) {
- if (preview == preview_)
- return;
-
- if (preview_) {
- RemoveChildView(preview_);
- DeleteTearWindow();
- }
- preview_ = preview;
- preview_tab_contents_ = preview_tab_contents;
- if (preview_) {
- AddChildView(preview_);
- CreateTearWindow();
- }
-
- Layout();
-
- if (preview_)
- tear_window_->Show(); // Show after we'ved positioned it in Layout.
-}
-
-void ContentsContainer::SetActiveTopMargin(int margin) {
- if (active_top_margin_ == margin)
- return;
-
- active_top_margin_ = margin;
- // Make sure we layout next time around. We need this in case our bounds
- // haven't changed.
- InvalidateLayout();
-}
-
-gfx::Rect ContentsContainer::GetPreviewBounds() {
- gfx::Point screen_loc;
- ConvertPointToScreen(this, &screen_loc);
- return gfx::Rect(screen_loc, size());
-}
-
-void ContentsContainer::Layout() {
- // The active view always gets the full bounds.
- active_->SetBounds(0, active_top_margin_, width(),
- std::max(0, height() - active_top_margin_));
-
- if (preview_) {
- preview_->SetBounds(0, 0, width(), height());
- PositionTearWindow();
- }
-
- // Need to invoke views::View in case any views whose bounds didn't change
- // still need a layout.
- views::View::Layout();
-}
-
-void ContentsContainer::CreateTearWindow() {
- DCHECK(preview_);
- tear_window_ = CreateTearWindowImpl();
-
- views::ImageView* image_view = new views::ImageView();
- image_view->SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_MATCH_PREVIEW_TEAR));
- tear_window_->SetContentsView(image_view);
-}
-
-#if defined(OS_WIN)
-
-ContentsContainer::TearWindow* ContentsContainer::CreateTearWindowImpl() {
- TearWindow* widget = new TearWindow(this);
- widget->Init(browser_view_->GetNativeHandle(), gfx::Rect());
- return widget;
-}
-
-#elif defined(OS_LINUX)
-
-ContentsContainer::TearWindow* ContentsContainer::CreateTearWindowImpl() {
- views::WidgetGtk* widget = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP);
- widget->MakeTransparent();
- widget->Init(NULL, gfx::Rect());
- gtk_util::StackPopupWindow(widget->GetNativeView(),
- GTK_WIDGET(browser_view_->GetNativeHandle()));
- return widget;
-}
-
-#endif
-
-void ContentsContainer::PositionTearWindow() {
- if (!tear_window_)
- return;
-
- gfx::Rect vis_bounds = GetVisibleBounds();
-
- gfx::Size pref = tear_window_->GetRootView()->GetPreferredSize();
- // Constrain to the the visible bounds as we may be given a different size
- // than is actually visible.
- pref.SetSize(std::min(pref.width(), vis_bounds.width()),
- std::min(pref.height(), vis_bounds.height()));
-
- gfx::Rect bounds(0, 0, pref.width(), pref.height());
- bounds.set_x(MirroredLeftPointForRect(bounds));
-
- gfx::Point origin(bounds.origin());
- views::View::ConvertPointToScreen(this, &origin);
-
- tear_window_->SetBounds(gfx::Rect(origin, pref));
-}
-
-void ContentsContainer::DeleteTearWindow() {
- if (!tear_window_)
- return;
-
- tear_window_->Close();
-#if defined(OS_WIN)
- tear_window_->set_contents_container(NULL);
-#endif
- // Close deletes the tear window.
- tear_window_ = NULL;
-}
-
-void ContentsContainer::TearWindowDestroyed() {
- tear_window_ = NULL;
-}
diff --git a/chrome/browser/views/frame/contents_container.h b/chrome/browser/views/frame/contents_container.h
index fe22d47..07b7983 100644
--- a/chrome/browser/views/frame/contents_container.h
+++ b/chrome/browser/views/frame/contents_container.h
@@ -6,81 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_CONTENTS_CONTAINER_H_
#pragma once
-#include "views/view.h"
-
-class BrowserView;
-class TabContents;
-
-namespace views {
-class Widget;
-}
-
-// ContentsContainer is responsible for managing the TabContents views.
-// ContentsContainer has up to two children: one for the currently active
-// TabContents and one for instant's TabContents.
-class ContentsContainer : public views::View {
- public:
- ContentsContainer(BrowserView* browser_view, views::View* active);
- virtual ~ContentsContainer();
-
- // Makes the preview view the active view and nulls out the old active view.
- // It's assumed the caller will delete or remove the old active view
- // separately.
- void MakePreviewContentsActiveContents();
-
- // Sets the preview view. This does not delete the old.
- void SetPreview(views::View* preview, TabContents* preview_tab_contents);
-
- TabContents* preview_tab_contents() const { return preview_tab_contents_; }
-
- // Sets the active top margin.
- void SetActiveTopMargin(int margin);
-
- // Returns the bounds of the preview. If the preview isn't active this
- // retuns the bounds the preview would be shown at.
- gfx::Rect GetPreviewBounds();
-
- // View overrides:
- virtual void Layout();
-
- private:
-#if defined(OS_WIN)
- class TearWindow;
-#else
- typedef views::Widget TearWindow;
-#endif
-
- // Creates and configures the tear window.
- void CreateTearWindow();
-
- // Creates and returns a new TearWindow.
- TearWindow* CreateTearWindowImpl();
-
- // Resets the bounds of the tear window.
- void PositionTearWindow();
-
- // Closes and deletes the tear window.
- void DeleteTearWindow();
-
- // Invoked when the tear window is destroyed.
- void TearWindowDestroyed();
-
- BrowserView* browser_view_;
-
- views::View* active_;
-
- views::View* preview_;
-
- TabContents* preview_tab_contents_;
-
- // Window used to show the page tear.
- TearWindow* tear_window_;
-
- // The margin between the top and the active view. This is used to make the
- // preview overlap the bookmark bar on the new tab page.
- int active_top_margin_;
-
- DISALLOW_COPY_AND_ASSIGN(ContentsContainer);
-};
+#include "chrome/browser/ui/views/frame/contents_container.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_CONTENTS_CONTAINER_H_
+
diff --git a/chrome/browser/views/frame/glass_browser_frame_view.cc b/chrome/browser/views/frame/glass_browser_frame_view.cc
deleted file mode 100644
index fdc1956..0000000
--- a/chrome/browser/views/frame/glass_browser_frame_view.cc
+++ /dev/null
@@ -1,511 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/glass_browser_frame_view.h"
-
-#include "app/resource_bundle.h"
-#include "app/theme_provider.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/themes/browser_theme_provider.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/tabs/side_tab_strip.h"
-#include "chrome/browser/views/tabs/tab.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "gfx/canvas_skia.h"
-#include "gfx/icon_util.h"
-#include "grit/app_resources.h"
-#include "grit/theme_resources.h"
-#include "views/window/client_view.h"
-#include "views/window/window_resources.h"
-
-HICON GlassBrowserFrameView::throbber_icons_[
- GlassBrowserFrameView::kThrobberIconCount];
-
-namespace {
-// There are 3 px of client edge drawn inside the outer frame borders.
-const int kNonClientBorderThickness = 3;
-// Vertical tabs have 4 px border.
-const int kNonClientVerticalTabStripBorderThickness = 4;
-// Besides the frame border, there's another 11 px of empty space atop the
-// window in restored mode, to use to drag the window around.
-const int kNonClientRestoredExtraThickness = 11;
-// In the window corners, the resize areas don't actually expand bigger, but the
-// 16 px at the end of the top and bottom edges triggers diagonal resizing.
-const int kResizeAreaCornerSize = 16;
-// The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
-// way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
-// user).
-const int kOTRBottomSpacing = 2;
-// There are 2 px on each side of the OTR avatar (between the frame border and
-// it on the left, and between it and the tabstrip on the right).
-const int kOTRSideSpacing = 2;
-// The content left/right images have a shadow built into them.
-const int kContentEdgeShadowThickness = 2;
-// The top 1 px of the tabstrip is shadow; in maximized mode we push this off
-// the top of the screen so the tabs appear flush against the screen edge.
-const int kTabstripTopShadowThickness = 1;
-// In restored mode, the New Tab button isn't at the same height as the caption
-// buttons, but the space will look cluttered if it actually slides under them,
-// so we stop it when the gap between the two is down to 5 px.
-const int kNewTabCaptionRestoredSpacing = 5;
-// In maximized mode, where the New Tab button and the caption buttons are at
-// similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
-// looking too cluttered.
-const int kNewTabCaptionMaximizedSpacing = 16;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// GlassBrowserFrameView, public:
-
-GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
- BrowserView* browser_view)
- : BrowserNonClientFrameView(),
- frame_(frame),
- browser_view_(browser_view),
- throbber_running_(false),
- throbber_frame_(0) {
- if (frame_->GetWindow()->GetDelegate()->ShouldShowWindowIcon())
- InitThrobberIcons();
-}
-
-GlassBrowserFrameView::~GlassBrowserFrameView() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// GlassBrowserFrameView, BrowserNonClientFrameView implementation:
-
-gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
- BaseTabStrip* tabstrip) const {
- if (browser_view_->UseVerticalTabs()) {
- gfx::Size ps = tabstrip->GetPreferredSize();
- return gfx::Rect(NonClientBorderThickness(),
- NonClientTopBorderHeight(false, false), ps.width(),
- browser_view_->height());
- }
- int minimize_button_offset = frame_->GetMinimizeButtonOffset();
- int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
- (otr_avatar_bounds_.right() + kOTRSideSpacing) :
- NonClientBorderThickness();
- // In RTL languages, we have moved an avatar icon left by the size of window
- // controls to prevent it from being rendered over them. So, we use its x
- // position to move this tab strip left when maximized. Also, we can render
- // a tab strip until the left end of this window without considering the size
- // of window controls in RTL languages.
- if (base::i18n::IsRTL()) {
- if (!browser_view_->ShouldShowOffTheRecordAvatar() &&
- frame_->GetWindow()->IsMaximized())
- tabstrip_x += otr_avatar_bounds_.x();
- minimize_button_offset = width();
- }
- int tabstrip_width = minimize_button_offset - tabstrip_x -
- (frame_->GetWindow()->IsMaximized() ?
- kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
- return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false),
- std::max(0, tabstrip_width),
- tabstrip->GetPreferredHeight());
-}
-
-int GlassBrowserFrameView::GetHorizontalTabStripVerticalOffset(
- bool restored) const {
- return NonClientTopBorderHeight(restored, true);
-}
-
-void GlassBrowserFrameView::UpdateThrobber(bool running) {
- if (throbber_running_) {
- if (running) {
- DisplayNextThrobberFrame();
- } else {
- StopThrobber();
- }
- } else if (running) {
- StartThrobber();
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// GlassBrowserFrameView, views::NonClientFrameView implementation:
-
-gfx::Rect GlassBrowserFrameView::GetBoundsForClientView() const {
- return client_view_bounds_;
-}
-
-bool GlassBrowserFrameView::AlwaysUseNativeFrame() const {
- return frame_->AlwaysUseNativeFrame();
-}
-
-gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const {
- HWND hwnd = frame_->GetWindow()->GetNativeWindow();
- if (!browser_view_->IsTabStripVisible() && hwnd) {
- // If we don't have a tabstrip, we're either a popup or an app window, in
- // which case we have a standard size non-client area and can just use
- // AdjustWindowRectEx to obtain it. We check for a non-NULL window handle in
- // case this gets called before the window is actually created.
- RECT rect = client_bounds.ToRECT();
- AdjustWindowRectEx(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE,
- GetWindowLong(hwnd, GWL_EXSTYLE));
- return gfx::Rect(rect);
- }
-
- int top_height = NonClientTopBorderHeight(false, false);
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
- std::max(0, client_bounds.y() - top_height),
- client_bounds.width() + (2 * border_thickness),
- client_bounds.height() + top_height + border_thickness);
-}
-
-int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
- // If the browser isn't in normal mode, we haven't customized the frame, so
- // Windows can figure this out. If the point isn't within our bounds, then
- // it's in the native portion of the frame, so again Windows can figure it
- // out.
- if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point))
- return HTNOWHERE;
-
- int frame_component =
- frame_->GetWindow()->GetClientView()->NonClientHitTest(point);
-
- // See if we're in the sysmenu region. We still have to check the tabstrip
- // first so that clicks in a tab don't get treated as sysmenu clicks.
- int nonclient_border_thickness = NonClientBorderThickness();
- if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME),
- GetSystemMetrics(SM_CXSMICON),
- GetSystemMetrics(SM_CYSMICON)).Contains(point))
- return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
-
- if (frame_component != HTNOWHERE)
- return frame_component;
-
- int frame_border_thickness = FrameBorderThickness();
- int window_component = GetHTComponentForFrame(point, frame_border_thickness,
- nonclient_border_thickness, frame_border_thickness,
- kResizeAreaCornerSize - frame_border_thickness,
- frame_->GetWindow()->GetDelegate()->CanResize());
- // Fall back to the caption if no other component matches.
- return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// GlassBrowserFrameView, views::View overrides:
-
-void GlassBrowserFrameView::Paint(gfx::Canvas* canvas) {
- if (!browser_view_->IsTabStripVisible())
- return; // Nothing is visible, so don't bother to paint.
-
- PaintToolbarBackground(canvas);
- if (browser_view_->ShouldShowOffTheRecordAvatar())
- PaintOTRAvatar(canvas);
- if (!frame_->GetWindow()->IsMaximized())
- PaintRestoredClientEdge(canvas);
-}
-
-void GlassBrowserFrameView::Layout() {
- LayoutOTRAvatar();
- LayoutClientView();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// GlassBrowserFrameView, private:
-
-int GlassBrowserFrameView::FrameBorderThickness() const {
- views::Window* window = frame_->GetWindow();
- return (window->IsMaximized() || window->IsFullscreen()) ?
- 0 : GetSystemMetrics(SM_CXSIZEFRAME);
-}
-
-int GlassBrowserFrameView::NonClientBorderThickness() const {
- views::Window* window = frame_->GetWindow();
- if (window->IsMaximized() || window->IsFullscreen())
- return 0;
-
- return browser_view_->UseVerticalTabs() ?
- kNonClientVerticalTabStripBorderThickness :
- kNonClientBorderThickness;
-}
-
-int GlassBrowserFrameView::NonClientTopBorderHeight(
- bool restored,
- bool ignore_vertical_tabs) const {
- if (!restored && frame_->GetWindow()->IsFullscreen())
- return 0;
- // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
- // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
- // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
- if (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs &&
- browser_view_->UseVerticalTabs())
- return GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
- return GetSystemMetrics(SM_CYSIZEFRAME) +
- ((!restored && browser_view_->IsMaximized()) ?
- -kTabstripTopShadowThickness : kNonClientRestoredExtraThickness);
-}
-
-void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
- ThemeProvider* tp = GetThemeProvider();
-
- gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
- gfx::Point toolbar_origin(toolbar_bounds.origin());
- View::ConvertPointToView(browser_view_, this, &toolbar_origin);
- toolbar_bounds.set_origin(toolbar_origin);
- int x = toolbar_bounds.x();
- int w = toolbar_bounds.width();
- int left_x = x - kContentEdgeShadowThickness;
-
- SkBitmap* theme_toolbar = tp->GetBitmapNamed(IDR_THEME_TOOLBAR);
- SkBitmap* toolbar_left = tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER);
- SkBitmap* toolbar_center = tp->GetBitmapNamed(IDR_CONTENT_TOP_CENTER);
-
- if (browser_view_->UseVerticalTabs()) {
- gfx::Point tabstrip_origin(browser_view_->tabstrip()->bounds().origin());
- View::ConvertPointToView(browser_view_, this, &tabstrip_origin);
- int y = tabstrip_origin.y();
-
- // Tile the toolbar image starting at the frame edge on the left and where
- // the horizontal tabstrip would be on the top.
- canvas->TileImageInt(*theme_toolbar, x,
- y - GetHorizontalTabStripVerticalOffset(false), x, y,
- w, theme_toolbar->height());
-
- // Draw left edge.
- int dest_y = y - kNonClientBorderThickness;
- canvas->DrawBitmapInt(*toolbar_left, 0, 0, kNonClientBorderThickness,
- kNonClientBorderThickness, left_x, dest_y,
- kNonClientBorderThickness, kNonClientBorderThickness,
- false);
-
- // Draw center edge. We need to draw a while line above the toolbar for the
- // image to overlay nicely.
- int center_offset =
- -kContentEdgeShadowThickness + kNonClientBorderThickness;
- canvas->FillRectInt(SK_ColorWHITE, x + center_offset, y - 1,
- w - (2 * center_offset), 1);
- canvas->TileImageInt(*toolbar_center, x + center_offset, dest_y,
- w - (2 * center_offset), toolbar_center->height());
-
- // Right edge.
- SkBitmap* toolbar_right = tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER);
- canvas->DrawBitmapInt(*toolbar_right,
- toolbar_right->width() - kNonClientBorderThickness, 0,
- kNonClientBorderThickness, kNonClientBorderThickness,
- x + w - center_offset, dest_y, kNonClientBorderThickness,
- kNonClientBorderThickness, false);
- } else {
- // Tile the toolbar image starting at the frame edge on the left and where
- // the tabstrip is on the top.
- int y = toolbar_bounds.y();
- int dest_y = y + (kFrameShadowThickness * 2);
- canvas->TileImageInt(*theme_toolbar, x,
- dest_y - GetHorizontalTabStripVerticalOffset(false), x,
- dest_y, w, theme_toolbar->height());
-
- // Draw rounded corners for the tab.
- SkBitmap* toolbar_left_mask =
- tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
- SkBitmap* toolbar_right_mask =
- tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
-
- // We mask out the corners by using the DestinationIn transfer mode,
- // which keeps the RGB pixels from the destination and the alpha from
- // the source.
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
-
- // Mask out the top left corner.
- canvas->DrawBitmapInt(*toolbar_left_mask, left_x, y, paint);
-
- // Mask out the top right corner.
- int right_x =
- x + w + kContentEdgeShadowThickness - toolbar_right_mask->width();
- canvas->DrawBitmapInt(*toolbar_right_mask, right_x, y, paint);
-
- // Draw left edge.
- canvas->DrawBitmapInt(*toolbar_left, left_x, y);
-
- // Draw center edge.
- canvas->TileImageInt(*toolbar_center, left_x + toolbar_left->width(), y,
- right_x - (left_x + toolbar_left->width()), toolbar_center->height());
-
- // Right edge.
- canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER),
- right_x, y);
- }
-
- // Draw the content/toolbar separator.
- canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
- x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness,
- w - (2 * kClientEdgeThickness), kClientEdgeThickness);
-}
-
-void GlassBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) {
- // In RTL mode, the avatar icon should be looking the opposite direction.
- canvas->Save();
- if (base::i18n::IsRTL()) {
- canvas->TranslateInt(width(), 0);
- canvas->ScaleInt(-1, 1);
- }
-
- SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
- int w = otr_avatar_bounds_.width();
- int h = otr_avatar_bounds_.height();
- canvas->DrawBitmapInt(otr_avatar_icon, 0,
- // Bias the rounding to select a region that's lower rather than higher,
- // as the shadows at the image top mean the apparent center is below the
- // real center.
- ((otr_avatar_icon.height() - otr_avatar_bounds_.height()) + 1) / 2, w, h,
- otr_avatar_bounds_.x(), otr_avatar_bounds_.y(), w, h, false);
-
- canvas->Restore();
-}
-
-void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
- ThemeProvider* tp = GetThemeProvider();
- gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
-
- // The client edges start below the toolbar upper corner images regardless
- // of how tall the toolbar itself is.
- int client_area_top = browser_view_->UseVerticalTabs() ?
- client_area_bounds.y() :
- (frame_->GetWindow()->GetClientView()->y() +
- browser_view_->GetToolbarBounds().y() +
- tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height());
- int client_area_bottom =
- std::max(client_area_top, height() - NonClientBorderThickness());
- int client_area_height = client_area_bottom - client_area_top;
-
- // Draw the client edge images.
- SkBitmap* right = tp->GetBitmapNamed(IDR_CONTENT_RIGHT_SIDE);
- canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
- right->width(), client_area_height);
- canvas->DrawBitmapInt(
- *tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
- client_area_bounds.right(), client_area_bottom);
- SkBitmap* bottom = tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_CENTER);
- canvas->TileImageInt(*bottom, client_area_bounds.x(),
- client_area_bottom, client_area_bounds.width(),
- bottom->height());
- SkBitmap* bottom_left =
- tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
- canvas->DrawBitmapInt(*bottom_left,
- client_area_bounds.x() - bottom_left->width(), client_area_bottom);
- SkBitmap* left = tp->GetBitmapNamed(IDR_CONTENT_LEFT_SIDE);
- canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
- client_area_top, left->width(), client_area_height);
-
- // Draw the toolbar color so that the client edges show the right color even
- // where not covered by the toolbar image. NOTE: We do this after drawing the
- // images because the images are meant to alpha-blend atop the frame whereas
- // these rects are meant to be fully opaque, without anything overlaid.
- SkColor toolbar_color = tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
- canvas->FillRectInt(toolbar_color,
- client_area_bounds.x() - kClientEdgeThickness, client_area_top,
- kClientEdgeThickness,
- client_area_bottom + kClientEdgeThickness - client_area_top);
- canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom,
- client_area_bounds.width(), kClientEdgeThickness);
- canvas->FillRectInt(toolbar_color, client_area_bounds.right(),
- client_area_top, kClientEdgeThickness,
- client_area_bottom + kClientEdgeThickness - client_area_top);
-}
-
-void GlassBrowserFrameView::LayoutOTRAvatar() {
- int otr_x = NonClientBorderThickness() + kOTRSideSpacing;
- // Move this avatar icon by the size of window controls to prevent it from
- // being rendered over them in RTL languages. This code also needs to adjust
- // the width of a tab strip to avoid decreasing this size twice. (See the
- // comment in GetBoundsForTabStrip().)
- if (base::i18n::IsRTL())
- otr_x += width() - frame_->GetMinimizeButtonOffset();
-
- SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
- int otr_bottom, otr_restored_y;
- if (browser_view_->UseVerticalTabs()) {
- otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing;
- otr_restored_y = kFrameShadowThickness;
- } else {
- otr_bottom = GetHorizontalTabStripVerticalOffset(false) +
- browser_view_->GetTabStripHeight() - kOTRBottomSpacing;
- otr_restored_y = otr_bottom - otr_avatar_icon.height();
- }
- int otr_y = frame_->GetWindow()->IsMaximized() ?
- (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) :
- otr_restored_y;
- otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_avatar_icon.width(),
- browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0);
-}
-
-void GlassBrowserFrameView::LayoutClientView() {
- client_view_bounds_ = CalculateClientAreaBounds(width(), height());
-}
-
-gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width,
- int height) const {
- if (!browser_view_->IsTabStripVisible())
- return gfx::Rect(0, 0, this->width(), this->height());
-
- int top_height = NonClientTopBorderHeight(false, false);
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(border_thickness, top_height,
- std::max(0, width - (2 * border_thickness)),
- std::max(0, height - top_height - border_thickness));
-}
-
-void GlassBrowserFrameView::StartThrobber() {
- if (!throbber_running_) {
- throbber_running_ = true;
- throbber_frame_ = 0;
- InitThrobberIcons();
- SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON,
- static_cast<WPARAM>(ICON_SMALL),
- reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
- }
-}
-
-void GlassBrowserFrameView::StopThrobber() {
- if (throbber_running_) {
- throbber_running_ = false;
-
- HICON frame_icon = NULL;
-
- // Check if hosted BrowserView has a window icon to use.
- if (browser_view_->ShouldShowWindowIcon()) {
- SkBitmap icon = browser_view_->GetWindowIcon();
- if (!icon.isNull())
- frame_icon = IconUtil::CreateHICONFromSkBitmap(icon);
- }
-
- // Fallback to class icon.
- if (!frame_icon) {
- frame_icon = reinterpret_cast<HICON>(GetClassLongPtr(
- frame_->GetWindow()->GetNativeWindow(), GCLP_HICONSM));
- }
-
- // This will reset the small icon which we set in the throbber code.
- // WM_SETICON with NULL icon restores the icon for title bar but not
- // for taskbar. See http://crbug.com/29996
- SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON,
- static_cast<WPARAM>(ICON_SMALL),
- reinterpret_cast<LPARAM>(frame_icon));
- }
-}
-
-void GlassBrowserFrameView::DisplayNextThrobberFrame() {
- throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount;
- SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON,
- static_cast<WPARAM>(ICON_SMALL),
- reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
-}
-
-// static
-void GlassBrowserFrameView::InitThrobberIcons() {
- static bool initialized = false;
- if (!initialized) {
- ResourceBundle &rb = ResourceBundle::GetSharedInstance();
- for (int i = 0; i < kThrobberIconCount; ++i) {
- throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i);
- DCHECK(throbber_icons_[i]);
- }
- initialized = true;
- }
-}
diff --git a/chrome/browser/views/frame/glass_browser_frame_view.h b/chrome/browser/views/frame/glass_browser_frame_view.h
index 0a39da1..397ef26 100644
--- a/chrome/browser/views/frame/glass_browser_frame_view.h
+++ b/chrome/browser/views/frame/glass_browser_frame_view.h
@@ -6,98 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_GLASS_BROWSER_FRAME_VIEW_H_
#pragma once
-#include "chrome/browser/views/frame/browser_frame_win.h"
-#include "chrome/browser/views/frame/browser_non_client_frame_view.h"
-#include "views/controls/button/button.h"
-#include "views/window/non_client_view.h"
-
-class BrowserView;
-class SkBitmap;
-
-class GlassBrowserFrameView : public BrowserNonClientFrameView {
- public:
- // Constructs a non-client view for an BrowserFrame.
- GlassBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
- virtual ~GlassBrowserFrameView();
-
- // Overridden from BrowserNonClientFrameView:
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
-
- // Overridden from views::NonClientFrameView:
- virtual gfx::Rect GetBoundsForClientView() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) { }
- virtual void EnableClose(bool enable) { }
- virtual void ResetWindowControls() { }
-
- protected:
- // Overridden from views::View:
- virtual void Paint(gfx::Canvas* canvas);
- virtual void Layout();
-
- private:
- // Returns the thickness of the border that makes up the window frame edges.
- // This does not include any client edge.
- int FrameBorderThickness() const;
-
- // Returns the thickness of the entire nonclient left, right, and bottom
- // borders, including both the window frame and any client edge.
- int NonClientBorderThickness() const;
-
- // Returns the height of the entire nonclient top border, including the window
- // frame, any title area, and any connected client edge. If |restored| is
- // true, acts as if the window is restored regardless of the real mode. If
- // |ignore_vertical_tabs| is true, acts as if vertical tabs are off regardless
- // of the real state.
- int NonClientTopBorderHeight(bool restored, bool ignore_vertical_tabs) const;
-
- // Paint various sub-components of this view.
- void PaintToolbarBackground(gfx::Canvas* canvas);
- void PaintOTRAvatar(gfx::Canvas* canvas);
- void PaintRestoredClientEdge(gfx::Canvas* canvas);
-
- // Layout various sub-components of this view.
- void LayoutOTRAvatar();
- void LayoutClientView();
-
- // Returns the bounds of the client area for the specified view size.
- gfx::Rect CalculateClientAreaBounds(int width, int height) const;
-
- // Starts/Stops the window throbber running.
- void StartThrobber();
- void StopThrobber();
-
- // Displays the next throbber frame.
- void DisplayNextThrobberFrame();
-
- // The layout rect of the OTR avatar icon, if visible.
- gfx::Rect otr_avatar_bounds_;
-
- // The frame that hosts this view.
- BrowserFrame* frame_;
-
- // The BrowserView hosted within this View.
- BrowserView* browser_view_;
-
- // The bounds of the ClientView.
- gfx::Rect client_view_bounds_;
-
- // Whether or not the window throbber is currently animating.
- bool throbber_running_;
-
- // The index of the current frame of the throbber animation.
- int throbber_frame_;
-
- static const int kThrobberIconCount = 24;
- static HICON throbber_icons_[kThrobberIconCount];
- static void InitThrobberIcons();
-
- DISALLOW_COPY_AND_ASSIGN(GlassBrowserFrameView);
-};
+#include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_GLASS_BROWSER_FRAME_VIEW_H_
+
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc
deleted file mode 100644
index 94d0ffa..0000000
--- a/chrome/browser/views/frame/opaque_browser_frame_view.cc
+++ /dev/null
@@ -1,1031 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/opaque_browser_frame_view.h"
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "app/theme_provider.h"
-#include "base/compiler_specific.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/themes/browser_theme_provider.h"
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "chrome/browser/views/toolbar_view.h"
-#include "gfx/canvas_skia.h"
-#include "gfx/font.h"
-#include "gfx/path.h"
-#include "grit/app_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-#include "views/controls/button/image_button.h"
-#include "views/controls/image_view.h"
-#include "views/widget/root_view.h"
-#include "views/window/window.h"
-#include "views/window/window_resources.h"
-#include "views/window/window_shape.h"
-
-#if defined(OS_LINUX)
-#include "views/window/hit_test.h"
-#endif
-
-namespace {
-// The frame border is only visible in restored mode and is hardcoded to 4 px on
-// each side regardless of the system window border size.
-const int kFrameBorderThickness = 4;
-// Besides the frame border, there's another 11 px of empty space atop the
-// window in restored mode, to use to drag the window around.
-const int kNonClientRestoredExtraThickness = 11;
-// While resize areas on Windows are normally the same size as the window
-// borders, our top area is shrunk by 1 px to make it easier to move the window
-// around with our thinner top grabbable strip. (Incidentally, our side and
-// bottom resize areas don't match the frame border thickness either -- they
-// span the whole nonclient area, so there's no "dead zone" for the mouse.)
-const int kTopResizeAdjust = 1;
-// In the window corners, the resize areas don't actually expand bigger, but the
-// 16 px at the end of each edge triggers diagonal resizing.
-const int kResizeAreaCornerSize = 16;
-// The titlebar never shrinks too short to show the caption button plus some
-// padding below it.
-const int kCaptionButtonHeightWithPadding = 19;
-// The content left/right images have a shadow built into them.
-const int kContentEdgeShadowThickness = 2;
-// The titlebar has a 2 px 3D edge along the top and bottom.
-const int kTitlebarTopAndBottomEdgeThickness = 2;
-// The icon is inset 2 px from the left frame border.
-const int kIconLeftSpacing = 2;
-// The icon never shrinks below 16 px on a side.
-const int kIconMinimumSize = 16;
-// There is a 4 px gap between the icon and the title text.
-const int kIconTitleSpacing = 4;
-// There is a 5 px gap between the title text and the caption buttons.
-const int kTitleLogoSpacing = 5;
-// The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
-// way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
-// user).
-const int kOTRBottomSpacing = 2;
-// There are 2 px on each side of the OTR avatar (between the frame border and
-// it on the left, and between it and the tabstrip on the right).
-const int kOTRSideSpacing = 2;
-// The top 1 px of the tabstrip is shadow; in maximized mode we push this off
-// the top of the screen so the tabs appear flush against the screen edge.
-const int kTabstripTopShadowThickness = 1;
-// In restored mode, the New Tab button isn't at the same height as the caption
-// buttons, but the space will look cluttered if it actually slides under them,
-// so we stop it when the gap between the two is down to 5 px.
-const int kNewTabCaptionRestoredSpacing = 5;
-// In maximized mode, where the New Tab button and the caption buttons are at
-// similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
-// looking too cluttered.
-const int kNewTabCaptionMaximizedSpacing = 16;
-// How far to indent the tabstrip from the left side of the screen when there
-// is no OTR icon.
-const int kTabStripIndent = 1;
-// Inset from the top of the toolbar/tabstrip to the shadow. Used only for
-// vertical tabs.
-const int kVerticalTabBorderInset = 3;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, public:
-
-OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
- BrowserView* browser_view)
- : BrowserNonClientFrameView(),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- minimize_button_(new views::ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- maximize_button_(new views::ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- restore_button_(new views::ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- close_button_(new views::ImageButton(this))),
- window_icon_(NULL),
- frame_(frame),
- browser_view_(browser_view) {
- ThemeProvider* tp = frame_->GetThemeProviderForFrame();
- SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
- SkBitmap* background =
- tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND);
- minimize_button_->SetImage(views::CustomButton::BS_NORMAL,
- tp->GetBitmapNamed(IDR_MINIMIZE));
- minimize_button_->SetImage(views::CustomButton::BS_HOT,
- tp->GetBitmapNamed(IDR_MINIMIZE_H));
- minimize_button_->SetImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_MINIMIZE_P));
- if (browser_view_->IsBrowserTypeNormal()) {
- minimize_button_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK));
- }
- minimize_button_->SetAccessibleName(
- l10n_util::GetString(IDS_ACCNAME_MINIMIZE));
- AddChildView(minimize_button_);
-
- maximize_button_->SetImage(views::CustomButton::BS_NORMAL,
- tp->GetBitmapNamed(IDR_MAXIMIZE));
- maximize_button_->SetImage(views::CustomButton::BS_HOT,
- tp->GetBitmapNamed(IDR_MAXIMIZE_H));
- maximize_button_->SetImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_MAXIMIZE_P));
- if (browser_view_->IsBrowserTypeNormal()) {
- maximize_button_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK));
- }
- maximize_button_->SetAccessibleName(
- l10n_util::GetString(IDS_ACCNAME_MAXIMIZE));
- AddChildView(maximize_button_);
-
- restore_button_->SetImage(views::CustomButton::BS_NORMAL,
- tp->GetBitmapNamed(IDR_RESTORE));
- restore_button_->SetImage(views::CustomButton::BS_HOT,
- tp->GetBitmapNamed(IDR_RESTORE_H));
- restore_button_->SetImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_RESTORE_P));
- if (browser_view_->IsBrowserTypeNormal()) {
- restore_button_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_RESTORE_BUTTON_MASK));
- }
- restore_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RESTORE));
- AddChildView(restore_button_);
-
- close_button_->SetImage(views::CustomButton::BS_NORMAL,
- tp->GetBitmapNamed(IDR_CLOSE));
- close_button_->SetImage(views::CustomButton::BS_HOT,
- tp->GetBitmapNamed(IDR_CLOSE_H));
- close_button_->SetImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_CLOSE_P));
- if (browser_view_->IsBrowserTypeNormal()) {
- close_button_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_CLOSE_BUTTON_MASK));
- }
- close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
- AddChildView(close_button_);
-
- // Initializing the TabIconView is expensive, so only do it if we need to.
- if (browser_view_->ShouldShowWindowIcon()) {
- window_icon_ = new TabIconView(this);
- window_icon_->set_is_light(true);
- AddChildView(window_icon_);
- window_icon_->Update();
- }
-}
-
-OpaqueBrowserFrameView::~OpaqueBrowserFrameView() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, BrowserNonClientFrameView implementation:
-
-gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip(
- BaseTabStrip* tabstrip) const {
- if (browser_view_->UseVerticalTabs()) {
- gfx::Size ps = tabstrip->GetPreferredSize();
- return gfx::Rect(NonClientBorderThickness(),
- NonClientTopBorderHeight(false, false), ps.width(),
- browser_view_->height());
- }
-
- int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
- (otr_avatar_bounds_.right() + kOTRSideSpacing) :
- NonClientBorderThickness() + kTabStripIndent;
-
- int tabstrip_width = minimize_button_->x() - tabstrip_x -
- (frame_->GetWindow()->IsMaximized() ?
- kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
- return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false),
- std::max(0, tabstrip_width), tabstrip->GetPreferredHeight());
-}
-
-int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset(
- bool restored) const {
- return NonClientTopBorderHeight(restored, true) + ((!restored &&
- (frame_->GetWindow()->IsMaximized() ||
- frame_->GetWindow()->IsFullscreen())) ?
- 0 : kNonClientRestoredExtraThickness);
-}
-
-void OpaqueBrowserFrameView::UpdateThrobber(bool running) {
- if (window_icon_)
- window_icon_->Update();
-}
-
-gfx::Size OpaqueBrowserFrameView::GetMinimumSize() {
- gfx::Size min_size(browser_view_->GetMinimumSize());
- int border_thickness = NonClientBorderThickness();
- min_size.Enlarge(2 * border_thickness,
- NonClientTopBorderHeight(false, false) + border_thickness);
-
- views::WindowDelegate* d = frame_->GetWindow()->GetDelegate();
- int min_titlebar_width = (2 * FrameBorderThickness(false)) +
- kIconLeftSpacing +
- (d->ShouldShowWindowIcon() ? (IconSize() + kTitleLogoSpacing) : 0);
-#if !defined(OS_CHROMEOS)
- min_titlebar_width +=
- minimize_button_->GetMinimumSize().width() +
- restore_button_->GetMinimumSize().width() +
- close_button_->GetMinimumSize().width();
-#endif
- min_size.set_width(std::max(min_size.width(), min_titlebar_width));
- return min_size;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, views::NonClientFrameView implementation:
-
-gfx::Rect OpaqueBrowserFrameView::GetBoundsForClientView() const {
- return client_view_bounds_;
-}
-
-bool OpaqueBrowserFrameView::AlwaysUseNativeFrame() const {
- return frame_->AlwaysUseNativeFrame();
-}
-
-bool OpaqueBrowserFrameView::AlwaysUseCustomFrame() const {
- return true;
-}
-
-gfx::Rect OpaqueBrowserFrameView::GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const {
- int top_height = NonClientTopBorderHeight(false, false);
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
- std::max(0, client_bounds.y() - top_height),
- client_bounds.width() + (2 * border_thickness),
- client_bounds.height() + top_height + border_thickness);
-}
-
-int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
- if (!bounds().Contains(point))
- return HTNOWHERE;
-
- int frame_component =
- frame_->GetWindow()->GetClientView()->NonClientHitTest(point);
-
- // See if we're in the sysmenu region. We still have to check the tabstrip
- // first so that clicks in a tab don't get treated as sysmenu clicks.
- gfx::Rect sysmenu_rect(IconBounds());
- // In maximized mode we extend the rect to the screen corner to take advantage
- // of Fitts' Law.
- if (frame_->GetWindow()->IsMaximized())
- sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom());
- sysmenu_rect.set_x(MirroredLeftPointForRect(sysmenu_rect));
- if (sysmenu_rect.Contains(point))
- return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
-
- if (frame_component != HTNOWHERE)
- return frame_component;
-
- // Then see if the point is within any of the window controls.
- if (close_button_->IsVisible() &&
- close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point))
- return HTCLOSE;
- if (restore_button_->IsVisible() &&
- restore_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
- point))
- return HTMAXBUTTON;
- if (maximize_button_->IsVisible() &&
- maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
- point))
- return HTMAXBUTTON;
- if (minimize_button_->IsVisible() &&
- minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
- point))
- return HTMINBUTTON;
-
- int window_component = GetHTComponentForFrame(point, TopResizeHeight(),
- NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
- frame_->GetWindow()->GetDelegate()->CanResize());
- // Fall back to the caption if no other component matches.
- return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
-}
-
-void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask) {
- DCHECK(window_mask);
-
- if (frame_->GetWindow()->IsMaximized() || frame_->GetWindow()->IsFullscreen())
- return;
-
- views::GetDefaultWindowMask(size, window_mask);
-}
-
-void OpaqueBrowserFrameView::EnableClose(bool enable) {
- close_button_->SetEnabled(enable);
-}
-
-void OpaqueBrowserFrameView::ResetWindowControls() {
- restore_button_->SetState(views::CustomButton::BS_NORMAL);
- minimize_button_->SetState(views::CustomButton::BS_NORMAL);
- maximize_button_->SetState(views::CustomButton::BS_NORMAL);
- // The close button isn't affected by this constraint.
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, views::View overrides:
-
-void OpaqueBrowserFrameView::Paint(gfx::Canvas* canvas) {
- views::Window* window = frame_->GetWindow();
- if (window->IsFullscreen())
- return; // Nothing is visible, so don't bother to paint.
-
- if (window->IsMaximized())
- PaintMaximizedFrameBorder(canvas);
- else
- PaintRestoredFrameBorder(canvas);
- PaintTitleBar(canvas);
- if (browser_view_->IsToolbarVisible())
- PaintToolbarBackground(canvas);
- if (browser_view_->ShouldShowOffTheRecordAvatar())
- PaintOTRAvatar(canvas);
- if (!window->IsMaximized())
- PaintRestoredClientEdge(canvas);
-}
-
-void OpaqueBrowserFrameView::Layout() {
- LayoutWindowControls();
- LayoutTitleBar();
- LayoutOTRAvatar();
- client_view_bounds_ = CalculateClientAreaBounds(width(), height());
-}
-
-bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const {
- // If the point is outside the bounds of the client area, claim it.
- bool in_nonclient = NonClientFrameView::HitTest(l);
- if (in_nonclient)
- return in_nonclient;
-
- // Otherwise claim it only if it's in a non-tab portion of the tabstrip.
- bool vertical_tabs = browser_view_->UseVerticalTabs();
- gfx::Rect tabstrip_bounds = browser_view_->tabstrip()->bounds();
- gfx::Point tabstrip_origin(tabstrip_bounds.origin());
- View::ConvertPointToView(frame_->GetWindow()->GetClientView(),
- this, &tabstrip_origin);
- tabstrip_bounds.set_origin(tabstrip_origin);
- if ((!vertical_tabs && l.y() > tabstrip_bounds.bottom()) ||
- (vertical_tabs && l.x() > tabstrip_bounds.right())) {
- return false;
- }
-
- // We convert from our parent's coordinates since we assume we fill its bounds
- // completely. We need to do this since we're not a parent of the tabstrip,
- // meaning ConvertPointToView would otherwise return something bogus.
- gfx::Point browser_view_point(l);
- View::ConvertPointToView(GetParent(), browser_view_, &browser_view_point);
- return browser_view_->IsPositionInWindowCaption(browser_view_point);
-}
-
-AccessibilityTypes::Role OpaqueBrowserFrameView::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_TITLEBAR;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, views::ButtonListener implementation:
-
-void OpaqueBrowserFrameView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- views::Window* window = frame_->GetWindow();
- if (sender == minimize_button_)
- window->Minimize();
- else if (sender == maximize_button_)
- window->Maximize();
- else if (sender == restore_button_)
- window->Restore();
- else if (sender == close_button_)
- window->Close();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, TabIconView::TabContentsProvider implementation:
-
-bool OpaqueBrowserFrameView::ShouldTabIconViewAnimate() const {
- // This function is queried during the creation of the window as the
- // TabIconView we host is initialized, so we need to NULL check the selected
- // TabContents because in this condition there is not yet a selected tab.
- TabContents* current_tab = browser_view_->GetSelectedTabContents();
- return current_tab ? current_tab->is_loading() : false;
-}
-
-SkBitmap OpaqueBrowserFrameView::GetFavIconForTabIconView() {
- return frame_->GetWindow()->GetDelegate()->GetWindowIcon();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, private:
-
-int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
- views::Window* window = frame_->GetWindow();
- return (!restored && (window->IsMaximized() || window->IsFullscreen())) ?
- 0 : kFrameBorderThickness;
-}
-
-int OpaqueBrowserFrameView::TopResizeHeight() const {
- return FrameBorderThickness(false) - kTopResizeAdjust;
-}
-
-int OpaqueBrowserFrameView::NonClientBorderThickness() const {
- // When we fill the screen, we don't show a client edge.
- views::Window* window = frame_->GetWindow();
- return FrameBorderThickness(false) +
- ((window->IsMaximized() || window->IsFullscreen()) ?
- 0 : kClientEdgeThickness);
-}
-
-int OpaqueBrowserFrameView::NonClientTopBorderHeight(
- bool restored,
- bool ignore_vertical_tabs) const {
- views::Window* window = frame_->GetWindow();
- if (window->GetDelegate()->ShouldShowWindowTitle() ||
- (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs &&
- browser_view_->UseVerticalTabs())) {
- return std::max(FrameBorderThickness(restored) + IconSize(),
- CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) +
- TitlebarBottomThickness(restored);
- }
-
- return FrameBorderThickness(restored) -
- ((browser_view_->IsTabStripVisible() && !restored &&
- window->IsMaximized()) ? kTabstripTopShadowThickness : 0);
-}
-
-int OpaqueBrowserFrameView::CaptionButtonY(bool restored) const {
- // Maximized buttons start at window top so that even if their images aren't
- // drawn flush with the screen edge, they still obey Fitts' Law.
- return (!restored && frame_->GetWindow()->IsMaximized()) ?
- FrameBorderThickness(false) : kFrameShadowThickness;
-}
-
-int OpaqueBrowserFrameView::TitlebarBottomThickness(bool restored) const {
- return kTitlebarTopAndBottomEdgeThickness +
- ((!restored && frame_->GetWindow()->IsMaximized()) ?
- 0 : kClientEdgeThickness);
-}
-
-int OpaqueBrowserFrameView::IconSize() const {
-#if defined(OS_WIN)
- // This metric scales up if either the titlebar height or the titlebar font
- // size are increased.
- return GetSystemMetrics(SM_CYSMICON);
-#else
- return std::max(BrowserFrame::GetTitleFont().GetHeight(), kIconMinimumSize);
-#endif
-}
-
-gfx::Rect OpaqueBrowserFrameView::IconBounds() const {
- int size = IconSize();
- int frame_thickness = FrameBorderThickness(false);
- int y;
- views::WindowDelegate* d = frame_->GetWindow()->GetDelegate();
- if (d->ShouldShowWindowIcon() || d->ShouldShowWindowTitle()) {
- // Our frame border has a different "3D look" than Windows'. Theirs has a
- // more complex gradient on the top that they push their icon/title below;
- // then the maximized window cuts this off and the icon/title are centered
- // in the remaining space. Because the apparent shape of our border is
- // simpler, using the same positioning makes things look slightly uncentered
- // with restored windows, so when the window is restored, instead of
- // calculating the remaining space from below the frame border, we calculate
- // from below the 3D edge.
- int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ?
- frame_thickness : kTitlebarTopAndBottomEdgeThickness;
- // When the icon is shorter than the minimum space we reserve for the
- // caption button, we vertically center it. We want to bias rounding to put
- // extra space above the icon, since the 3D edge (+ client edge, for
- // restored windows) below looks (to the eye) more like additional space
- // than does the 3D edge (or nothing at all, for maximized windows) above;
- // hence the +1.
- y = unavailable_px_at_top + (NonClientTopBorderHeight(false, false) -
- unavailable_px_at_top - size - TitlebarBottomThickness(false) + 1) / 2;
- } else {
- // For "browser mode" windows, we use the native positioning, which is just
- // below the top frame border.
- y = frame_thickness;
- }
- return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size);
-}
-
-void OpaqueBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
- ThemeProvider* tp = GetThemeProvider();
-
- SkBitmap* top_left_corner = tp->GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER);
- SkBitmap* top_right_corner =
- tp->GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER);
- SkBitmap* top_edge = tp->GetBitmapNamed(IDR_WINDOW_TOP_CENTER);
- SkBitmap* right_edge = tp->GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE);
- SkBitmap* left_edge = tp->GetBitmapNamed(IDR_WINDOW_LEFT_SIDE);
- SkBitmap* bottom_left_corner =
- tp->GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER);
- SkBitmap* bottom_right_corner =
- tp->GetBitmapNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER);
- SkBitmap* bottom_edge = tp->GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER);
-
- // Window frame mode and color.
- SkBitmap* theme_frame;
- SkColor frame_color;
- if (!browser_view_->IsBrowserTypeNormal()) {
- // Never theme app and popup windows.
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- bool is_off_the_record = browser_view_->IsOffTheRecord();
- if (ShouldPaintAsActive()) {
- theme_frame = rb.GetBitmapNamed(is_off_the_record ?
- IDR_THEME_FRAME_INCOGNITO : IDR_FRAME);
- frame_color = is_off_the_record ?
- ResourceBundle::frame_color_incognito :
- ResourceBundle::frame_color;
- } else {
- theme_frame = rb.GetBitmapNamed(is_off_the_record ?
- IDR_THEME_FRAME_INCOGNITO_INACTIVE :
- IDR_THEME_FRAME_INACTIVE);
- frame_color = is_off_the_record ?
- ResourceBundle::frame_color_incognito_inactive :
- ResourceBundle::frame_color_inactive;
- }
- } else if (!browser_view_->IsOffTheRecord()) {
- if (ShouldPaintAsActive()) {
- theme_frame = tp->GetBitmapNamed(IDR_THEME_FRAME);
- frame_color = tp->GetColor(BrowserThemeProvider::COLOR_FRAME);
- } else {
- theme_frame = tp->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
- frame_color = tp->GetColor(BrowserThemeProvider::COLOR_FRAME_INACTIVE);
- }
- } else if (ShouldPaintAsActive()) {
- theme_frame = tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO);
- frame_color = tp->GetColor(BrowserThemeProvider::COLOR_FRAME_INCOGNITO);
- } else {
- theme_frame = tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO_INACTIVE);
- frame_color = tp->GetColor(
- BrowserThemeProvider::COLOR_FRAME_INCOGNITO_INACTIVE);
- }
-
- // Fill with the frame color first so we have a constant background for
- // areas not covered by the theme image.
- canvas->FillRectInt(frame_color, 0, 0, width(), theme_frame->height());
- // Now fill down the sides.
- canvas->FillRectInt(frame_color, 0, theme_frame->height(), left_edge->width(),
- height() - theme_frame->height());
- canvas->FillRectInt(frame_color, width() - right_edge->width(),
- theme_frame->height(), right_edge->width(),
- height() - theme_frame->height());
- // Now fill the bottom area.
- canvas->FillRectInt(frame_color, left_edge->width(),
- height() - bottom_edge->height(),
- width() - left_edge->width() - right_edge->width(),
- bottom_edge->height());
-
- // Draw the theme frame.
- canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height());
-
- // Draw the theme frame overlay.
- if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) &&
- browser_view_->IsBrowserTypeNormal() &&
- !browser_view_->IsOffTheRecord()) {
- canvas->DrawBitmapInt(*tp->GetBitmapNamed(ShouldPaintAsActive() ?
- IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE), 0, 0);
- }
-
- // Top.
- int top_left_height = std::min(top_left_corner->height(),
- height() - bottom_left_corner->height());
- canvas->DrawBitmapInt(*top_left_corner, 0, 0, top_left_corner->width(),
- top_left_height, 0, 0, top_left_corner->width(), top_left_height, false);
- canvas->TileImageInt(*top_edge, top_left_corner->width(), 0,
- width() - top_right_corner->width(), top_edge->height());
- int top_right_height = std::min(top_right_corner->height(),
- height() - bottom_right_corner->height());
- canvas->DrawBitmapInt(*top_right_corner, 0, 0, top_right_corner->width(),
- top_right_height, width() - top_right_corner->width(), 0,
- top_right_corner->width(), top_right_height, false);
- // Note: When we don't have a toolbar, we need to draw some kind of bottom
- // edge here. Because the App Window graphics we use for this have an
- // attached client edge and their sizing algorithm is a little involved, we do
- // all this in PaintRestoredClientEdge().
-
- // Right.
- canvas->TileImageInt(*right_edge, width() - right_edge->width(),
- top_right_height, right_edge->width(),
- height() - top_right_height - bottom_right_corner->height());
-
- // Bottom.
- canvas->DrawBitmapInt(*bottom_right_corner,
- width() - bottom_right_corner->width(),
- height() - bottom_right_corner->height());
- canvas->TileImageInt(*bottom_edge, bottom_left_corner->width(),
- height() - bottom_edge->height(),
- width() - bottom_left_corner->width() - bottom_right_corner->width(),
- bottom_edge->height());
- canvas->DrawBitmapInt(*bottom_left_corner, 0,
- height() - bottom_left_corner->height());
-
- // Left.
- canvas->TileImageInt(*left_edge, 0, top_left_height, left_edge->width(),
- height() - top_left_height - bottom_left_corner->height());
-}
-
-
-void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
- ThemeProvider* tp = GetThemeProvider();
- views::Window* window = frame_->GetWindow();
-
- // Window frame mode and color
- SkBitmap* theme_frame;
- // Never theme app and popup windows.
- if (!browser_view_->IsBrowserTypeNormal()) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- theme_frame = rb.GetBitmapNamed(ShouldPaintAsActive() ?
- IDR_FRAME : IDR_FRAME_INACTIVE);
- } else if (!browser_view_->IsOffTheRecord()) {
- theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ?
- IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE);
- } else {
- theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ?
- IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME_INCOGNITO_INACTIVE);
- }
- // Draw the theme frame. It must be aligned with the tabstrip as if we were
- // in restored mode. Note that the top of the tabstrip is
- // kTabstripTopShadowThickness px off the top of the screen.
- int theme_background_y = -(GetHorizontalTabStripVerticalOffset(true) +
- kTabstripTopShadowThickness);
- canvas->TileImageInt(*theme_frame, 0, theme_background_y, width(),
- theme_frame->height());
-
- // Draw the theme frame overlay
- if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) &&
- browser_view_->IsBrowserTypeNormal()) {
- SkBitmap* theme_overlay = tp->GetBitmapNamed(ShouldPaintAsActive() ?
- IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE);
- canvas->DrawBitmapInt(*theme_overlay, 0, theme_background_y);
- }
-
- if (!browser_view_->IsToolbarVisible()) {
- // There's no toolbar to edge the frame border, so we need to draw a bottom
- // edge. The graphic we use for this has a built in client edge, so we clip
- // it off the bottom.
- SkBitmap* top_center =
- tp->GetBitmapNamed(IDR_APP_TOP_CENTER);
- int edge_height = top_center->height() - kClientEdgeThickness;
- canvas->TileImageInt(*top_center, 0,
- window->GetClientView()->y() - edge_height, width(), edge_height);
- }
-}
-
-void OpaqueBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) {
- // The window icon is painted by the TabIconView.
- views::WindowDelegate* d = frame_->GetWindow()->GetDelegate();
- if (d->ShouldShowWindowTitle()) {
- canvas->DrawStringInt(d->GetWindowTitle(), BrowserFrame::GetTitleFont(),
- SK_ColorWHITE, MirroredLeftPointForRect(title_bounds_),
- title_bounds_.y(), title_bounds_.width(), title_bounds_.height());
- /* TODO(pkasting): If this window is active, we should also draw a drop
- * shadow on the title. This is tricky, because we don't want to hardcode a
- * shadow color (since we want to work with various themes), but we can't
- * alpha-blend either (since the Windows text APIs don't really do this).
- * So we'd need to sample the background color at the right location and
- * synthesize a good shadow color. */
- }
-}
-
-void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
- gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
- if (toolbar_bounds.IsEmpty())
- return;
- gfx::Point toolbar_origin(toolbar_bounds.origin());
- ConvertPointToView(browser_view_, this, &toolbar_origin);
- toolbar_bounds.set_origin(toolbar_origin);
-
- int x = toolbar_bounds.x();
- int w = toolbar_bounds.width();
- int y, h;
- if (browser_view_->UseVerticalTabs()) {
- gfx::Point tabstrip_origin(browser_view_->tabstrip()->bounds().origin());
- ConvertPointToView(browser_view_, this, &tabstrip_origin);
- y = tabstrip_origin.y() - kVerticalTabBorderInset;
- h = toolbar_bounds.bottom() - y;
- } else {
- y = toolbar_bounds.y();
- h = toolbar_bounds.bottom();
- }
-
- // Gross hack: We split the toolbar images into two pieces, since sometimes
- // (popup mode) the toolbar isn't tall enough to show the whole image. The
- // split happens between the top shadow section and the bottom gradient
- // section so that we never break the gradient.
- int split_point = kFrameShadowThickness * 2;
- int bottom_y = y + split_point;
- ThemeProvider* tp = GetThemeProvider();
- SkBitmap* toolbar_left = tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER);
- int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point;
-
- // Split our canvas out so we can mask out the corners of the toolbar
- // without masking out the frame.
- canvas->SaveLayerAlpha(
- 255, gfx::Rect(x - kClientEdgeThickness, y, w + kClientEdgeThickness * 3,
- h));
- canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
-
- SkColor theme_toolbar_color =
- tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
- canvas->FillRectInt(theme_toolbar_color, x, bottom_y, w, bottom_edge_height);
-
- // Tile the toolbar image starting at the frame edge on the left and where the
- // horizontal tabstrip is (or would be) on the top.
- SkBitmap* theme_toolbar = tp->GetBitmapNamed(IDR_THEME_TOOLBAR);
- canvas->TileImageInt(*theme_toolbar, x,
- bottom_y - GetHorizontalTabStripVerticalOffset(false), x,
- bottom_y, w, theme_toolbar->height());
-
- // Draw rounded corners for the tab.
- SkBitmap* toolbar_left_mask =
- tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
- SkBitmap* toolbar_right_mask =
- tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
-
- // We mask out the corners by using the DestinationIn transfer mode,
- // which keeps the RGB pixels from the destination and the alpha from
- // the source.
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
-
- // Mask the left edge.
- int left_x = x - kContentEdgeShadowThickness;
- canvas->DrawBitmapInt(*toolbar_left_mask, 0, 0, toolbar_left_mask->width(),
- split_point, left_x, y, toolbar_left_mask->width(),
- split_point, false, paint);
- canvas->DrawBitmapInt(*toolbar_left_mask, 0,
- toolbar_left_mask->height() - bottom_edge_height,
- toolbar_left_mask->width(), bottom_edge_height, left_x, bottom_y,
- toolbar_left_mask->width(), bottom_edge_height, false, paint);
-
- // Mask the right edge.
- int right_x =
- x + w - toolbar_right_mask->width() + kContentEdgeShadowThickness;
- canvas->DrawBitmapInt(*toolbar_right_mask, 0, 0, toolbar_right_mask->width(),
- split_point, right_x, y, toolbar_right_mask->width(),
- split_point, false, paint);
- canvas->DrawBitmapInt(*toolbar_right_mask, 0,
- toolbar_right_mask->height() - bottom_edge_height,
- toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y,
- toolbar_right_mask->width(), bottom_edge_height, false, paint);
- canvas->Restore();
-
- canvas->DrawBitmapInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point,
- left_x, y, toolbar_left->width(), split_point, false);
- canvas->DrawBitmapInt(*toolbar_left, 0,
- toolbar_left->height() - bottom_edge_height, toolbar_left->width(),
- bottom_edge_height, left_x, bottom_y, toolbar_left->width(),
- bottom_edge_height, false);
-
- SkBitmap* toolbar_center =
- tp->GetBitmapNamed(IDR_CONTENT_TOP_CENTER);
- canvas->TileImageInt(*toolbar_center, 0, 0, left_x + toolbar_left->width(),
- y, right_x - (left_x + toolbar_left->width()),
- split_point);
-
- SkBitmap* toolbar_right = tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER);
- canvas->DrawBitmapInt(*toolbar_right, 0, 0, toolbar_right->width(),
- split_point, right_x, y, toolbar_right->width(), split_point, false);
- canvas->DrawBitmapInt(*toolbar_right, 0,
- toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
- bottom_edge_height, right_x, bottom_y, toolbar_right->width(),
- bottom_edge_height, false);
-
- // Draw the content/toolbar separator.
- canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
- x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness,
- w - (2 * kClientEdgeThickness), kClientEdgeThickness);
-}
-
-void OpaqueBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) {
- // In RTL mode, the avatar icon should be looking the opposite direction.
- canvas->Save();
- if (base::i18n::IsRTL()) {
- canvas->TranslateInt(width(), 0);
- canvas->ScaleInt(-1, 1);
- }
-
- SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
- int w = otr_avatar_bounds_.width();
- int h = otr_avatar_bounds_.height();
- canvas->DrawBitmapInt(otr_avatar_icon, 0,
- // Bias the rounding to select a region that's lower rather than higher,
- // as the shadows at the image top mean the apparent center is below the
- // real center.
- ((otr_avatar_icon.height() - otr_avatar_bounds_.height()) + 1) / 2, w, h,
- otr_avatar_bounds_.x(), otr_avatar_bounds_.y(), w, h, false);
-
- canvas->Restore();
-}
-
-void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
- ThemeProvider* tp = GetThemeProvider();
- int client_area_top = frame_->GetWindow()->GetClientView()->y();
- int image_top = client_area_top;
-
- gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
- SkColor toolbar_color = tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
-
- if (browser_view_->IsToolbarVisible()) {
- // The client edge images always start below the toolbar corner images. The
- // client edge filled rects start there or at the bottom of the tooolbar,
- // whichever is shorter.
- gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
- image_top += toolbar_bounds.y() +
- tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height();
- client_area_top = std::min(image_top,
- client_area_top + toolbar_bounds.bottom() - kClientEdgeThickness);
- if (browser_view_->UseVerticalTabs()) {
- client_area_top -= kVerticalTabBorderInset;
- image_top -= kVerticalTabBorderInset;
- }
- } else if (!browser_view_->IsTabStripVisible()) {
- // The toolbar isn't going to draw a client edge for us, so draw one
- // ourselves.
- SkBitmap* top_left = tp->GetBitmapNamed(IDR_APP_TOP_LEFT);
- SkBitmap* top_center = tp->GetBitmapNamed(IDR_APP_TOP_CENTER);
- SkBitmap* top_right = tp->GetBitmapNamed(IDR_APP_TOP_RIGHT);
- int top_edge_y = client_area_top - top_center->height();
- int height = client_area_top - top_edge_y;
-
- canvas->DrawBitmapInt(*top_left, 0, 0, top_left->width(), height,
- client_area_bounds.x() - top_left->width(), top_edge_y,
- top_left->width(), height, false);
- canvas->TileImageInt(*top_center, 0, 0, client_area_bounds.x(), top_edge_y,
- client_area_bounds.width(), std::min(height, top_center->height()));
- canvas->DrawBitmapInt(*top_right, 0, 0, top_right->width(), height,
- client_area_bounds.right(), top_edge_y,
- top_right->width(), height, false);
-
- // Draw the toolbar color across the top edge.
- canvas->FillRectInt(toolbar_color,
- client_area_bounds.x() - kClientEdgeThickness,
- client_area_top - kClientEdgeThickness,
- client_area_bounds.width() + (2 * kClientEdgeThickness),
- kClientEdgeThickness);
- }
-
- int client_area_bottom =
- std::max(client_area_top, height() - NonClientBorderThickness());
- int image_height = client_area_bottom - image_top;
-
- // Draw the client edge images.
- // Draw the client edge images.
- SkBitmap* right = tp->GetBitmapNamed(IDR_CONTENT_RIGHT_SIDE);
- canvas->TileImageInt(*right, client_area_bounds.right(), image_top,
- right->width(), image_height);
- canvas->DrawBitmapInt(
- *tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
- client_area_bounds.right(), client_area_bottom);
- SkBitmap* bottom = tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_CENTER);
- canvas->TileImageInt(*bottom, client_area_bounds.x(),
- client_area_bottom, client_area_bounds.width(),
- bottom->height());
- SkBitmap* bottom_left =
- tp->GetBitmapNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
- canvas->DrawBitmapInt(*bottom_left,
- client_area_bounds.x() - bottom_left->width(), client_area_bottom);
- SkBitmap* left = tp->GetBitmapNamed(IDR_CONTENT_LEFT_SIDE);
- canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
- image_top, left->width(), image_height);
-
- // Draw the toolbar color so that the client edges show the right color even
- // where not covered by the toolbar image. NOTE: We do this after drawing the
- // images because the images are meant to alpha-blend atop the frame whereas
- // these rects are meant to be fully opaque, without anything overlaid.
- canvas->FillRectInt(toolbar_color,
- client_area_bounds.x() - kClientEdgeThickness, client_area_top,
- kClientEdgeThickness,
- client_area_bottom + kClientEdgeThickness - client_area_top);
- canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom,
- client_area_bounds.width(), kClientEdgeThickness);
- canvas->FillRectInt(toolbar_color, client_area_bounds.right(),
- client_area_top, kClientEdgeThickness,
- client_area_bottom + kClientEdgeThickness - client_area_top);
-}
-
-void OpaqueBrowserFrameView::LayoutWindowControls() {
- bool is_maximized = frame_->GetWindow()->IsMaximized();
- close_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
- views::ImageButton::ALIGN_BOTTOM);
- int caption_y = CaptionButtonY(false);
- // There should always be the same number of non-shadow pixels visible to the
- // side of the caption buttons. In maximized mode we extend the rightmost
- // button to the screen corner to obey Fitts' Law.
- int right_extra_width = is_maximized ?
- (kFrameBorderThickness - kFrameShadowThickness) : 0;
- gfx::Size close_button_size = close_button_->GetPreferredSize();
- close_button_->SetBounds(width() - FrameBorderThickness(false) -
- right_extra_width - close_button_size.width(), caption_y,
- close_button_size.width() + right_extra_width,
- close_button_size.height());
-
-#if defined(OS_CHROMEOS)
- // LayoutWindowControls could be triggered from WindowGtk::UpdateWindowTitle,
- // which could happen when user navigates in fullscreen mode. And because
- // BrowserFrameChromeos::IsMaximized return false for fullscreen mode, we
- // explicitly test fullscreen mode here and make it use the same code path
- // as maximized mode.
- // TODO(oshima): Optimize the relayout logic to defer the frame view's
- // relayout until it is necessary, i.e when it becomes visible.
- if (is_maximized || frame_->GetWindow()->IsFullscreen()) {
- minimize_button_->SetVisible(false);
- restore_button_->SetVisible(false);
- maximize_button_->SetVisible(false);
-
- if (browser_view_->browser()->type() == Browser::TYPE_DEVTOOLS) {
- close_button_->SetVisible(true);
- minimize_button_->SetBounds(close_button_->bounds().x(), 0, 0, 0);
- } else {
- close_button_->SetVisible(false);
- // Set the bounds of the minimize button so that we don't have to change
- // other places that rely on the bounds. Put it slightly to the right
- // of the edge of the view, so that when we remove the spacing it lines
- // up with the edge.
- minimize_button_->SetBounds(width() - FrameBorderThickness(false) +
- kNewTabCaptionMaximizedSpacing, 0, 0, 0);
- }
-
- return;
- } else {
- close_button_->SetVisible(true);
- }
-#endif
-
- // When the window is restored, we show a maximized button; otherwise, we show
- // a restore button.
- bool is_restored = !is_maximized && !frame_->GetWindow()->IsMinimized();
- views::ImageButton* invisible_button = is_restored ?
- restore_button_ : maximize_button_;
- invisible_button->SetVisible(false);
-
- views::ImageButton* visible_button = is_restored ?
- maximize_button_ : restore_button_;
- visible_button->SetVisible(true);
- visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
- views::ImageButton::ALIGN_BOTTOM);
- gfx::Size visible_button_size = visible_button->GetPreferredSize();
- visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
- caption_y, visible_button_size.width(),
- visible_button_size.height());
-
- minimize_button_->SetVisible(true);
- minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
- views::ImageButton::ALIGN_BOTTOM);
- gfx::Size minimize_button_size = minimize_button_->GetPreferredSize();
- minimize_button_->SetBounds(
- visible_button->x() - minimize_button_size.width(), caption_y,
- minimize_button_size.width(),
- minimize_button_size.height());
-}
-
-void OpaqueBrowserFrameView::LayoutTitleBar() {
- // The window title is based on the calculated icon position, even when there
- // is no icon.
- gfx::Rect icon_bounds(IconBounds());
- views::WindowDelegate* d = frame_->GetWindow()->GetDelegate();
- if (d->ShouldShowWindowIcon())
- window_icon_->SetBounds(icon_bounds);
-
- // Size the title, if visible.
- if (d->ShouldShowWindowTitle()) {
- int title_x = d->ShouldShowWindowIcon() ?
- icon_bounds.right() + kIconTitleSpacing : icon_bounds.x();
- int title_height = BrowserFrame::GetTitleFont().GetHeight();
- // We bias the title position so that when the difference between the icon
- // and title heights is odd, the extra pixel of the title is above the
- // vertical midline rather than below. This compensates for how the icon is
- // already biased downwards (see IconBounds()) and helps prevent descenders
- // on the title from overlapping the 3D edge at the bottom of the titlebar.
- title_bounds_.SetRect(title_x,
- icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2),
- std::max(0, minimize_button_->x() - kTitleLogoSpacing - title_x),
- title_height);
- }
-}
-
-void OpaqueBrowserFrameView::LayoutOTRAvatar() {
- SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
- int otr_bottom, otr_restored_y;
- if (browser_view_->UseVerticalTabs()) {
- otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing;
- otr_restored_y = kFrameShadowThickness;
- } else {
- otr_bottom = GetHorizontalTabStripVerticalOffset(false) +
- browser_view_->GetTabStripHeight() - kOTRBottomSpacing;
- otr_restored_y = otr_bottom - otr_avatar_icon.height();
- }
- int otr_y = frame_->GetWindow()->IsMaximized() ?
- (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) :
- otr_restored_y;
- otr_avatar_bounds_.SetRect(NonClientBorderThickness() + kOTRSideSpacing,
- otr_y, otr_avatar_icon.width(),
- browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0);
-}
-
-gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width,
- int height) const {
- int top_height = NonClientTopBorderHeight(false, false);
- int border_thickness = NonClientBorderThickness();
- return gfx::Rect(border_thickness, top_height,
- std::max(0, width - (2 * border_thickness)),
- std::max(0, height - top_height - border_thickness));
-}
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.h b/chrome/browser/views/frame/opaque_browser_frame_view.h
index 483693e..3e11721 100644
--- a/chrome/browser/views/frame/opaque_browser_frame_view.h
+++ b/chrome/browser/views/frame/opaque_browser_frame_view.h
@@ -6,143 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_H_
#pragma once
-#include "chrome/browser/views/frame/browser_frame.h"
-#include "chrome/browser/views/frame/browser_non_client_frame_view.h"
-#include "chrome/browser/views/tab_icon_view.h"
-#include "views/controls/button/button.h"
-#include "views/window/non_client_view.h"
-
-class BaseTabStrip;
-class BrowserView;
-namespace gfx {
-class Font;
-}
-class TabContents;
-namespace views {
-class ImageButton;
-class ImageView;
-}
-
-class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
- public views::ButtonListener,
- public TabIconView::TabIconViewModel {
- public:
- // Constructs a non-client view for an BrowserFrame.
- OpaqueBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
- virtual ~OpaqueBrowserFrameView();
-
- // Overridden from BrowserNonClientFrameView:
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
- virtual gfx::Size GetMinimumSize();
-
- protected:
- // Overridden from views::NonClientFrameView:
- virtual gfx::Rect GetBoundsForClientView() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual bool AlwaysUseCustomFrame() const;
- virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
- virtual void EnableClose(bool enable);
- virtual void ResetWindowControls();
-
- // Overridden from views::View:
- virtual void Paint(gfx::Canvas* canvas);
- virtual void Layout();
- virtual bool HitTest(const gfx::Point& l) const;
- virtual AccessibilityTypes::Role GetAccessibleRole();
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- // Overridden from TabIconView::TabIconViewModel:
- virtual bool ShouldTabIconViewAnimate() const;
- virtual SkBitmap GetFavIconForTabIconView();
-
- private:
- // Returns the thickness of the border that makes up the window frame edges.
- // This does not include any client edge. If |restored| is true, acts as if
- // the window is restored regardless of the real mode.
- int FrameBorderThickness(bool restored) const;
-
- // Returns the height of the top resize area. This is smaller than the frame
- // border height in order to increase the window draggable area.
- int TopResizeHeight() const;
-
- // Returns the thickness of the entire nonclient left, right, and bottom
- // borders, including both the window frame and any client edge.
- int NonClientBorderThickness() const;
-
- // Returns the height of the entire nonclient top border, including the window
- // frame, any title area, and any connected client edge. If |restored| is
- // true, acts as if the window is restored regardless of the real mode. If
- // |ignore_vertical_tabs| is true, acts as if vertical tabs are off regardless
- // of the real state.
- int NonClientTopBorderHeight(bool restored, bool ignore_vertical_tabs) const;
-
- // Returns the y-coordinate of the caption buttons. If |restored| is true,
- // acts as if the window is restored regardless of the real mode.
- int CaptionButtonY(bool restored) const;
-
- // Returns the thickness of the 3D edge along the bottom of the titlebar. If
- // |restored| is true, acts as if the window is restored regardless of the
- // real mode.
- int TitlebarBottomThickness(bool restored) const;
-
- // Returns the size of the titlebar icon. This is used even when the icon is
- // not shown, e.g. to set the titlebar height.
- int IconSize() const;
-
- // Returns the bounds of the titlebar icon (or where the icon would be if
- // there was one).
- gfx::Rect IconBounds() const;
-
- // Paint various sub-components of this view. The *FrameBorder() functions
- // also paint the background of the titlebar area, since the top frame border
- // and titlebar background are a contiguous component.
- void PaintRestoredFrameBorder(gfx::Canvas* canvas);
- void PaintMaximizedFrameBorder(gfx::Canvas* canvas);
- void PaintTitleBar(gfx::Canvas* canvas);
- void PaintToolbarBackground(gfx::Canvas* canvas);
- void PaintOTRAvatar(gfx::Canvas* canvas);
- void PaintRestoredClientEdge(gfx::Canvas* canvas);
-
- // Layout various sub-components of this view.
- void LayoutWindowControls();
- void LayoutTitleBar();
- void LayoutOTRAvatar();
-
- // Returns the bounds of the client area for the specified view size.
- gfx::Rect CalculateClientAreaBounds(int width, int height) const;
-
- // The layout rect of the title, if visible.
- gfx::Rect title_bounds_;
-
- // The layout rect of the OTR avatar icon, if visible.
- gfx::Rect otr_avatar_bounds_;
-
- // Window controls.
- views::ImageButton* minimize_button_;
- views::ImageButton* maximize_button_;
- views::ImageButton* restore_button_;
- views::ImageButton* close_button_;
-
- // The Window icon.
- TabIconView* window_icon_;
-
- // The frame that hosts this view.
- BrowserFrame* frame_;
-
- // The BrowserView hosted within this View.
- BrowserView* browser_view_;
-
- // The bounds of the ClientView.
- gfx::Rect client_view_bounds_;
-
- DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameView);
-};
+#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_H_
+
diff --git a/chrome/browser/views/frame/popup_non_client_frame_view.cc b/chrome/browser/views/frame/popup_non_client_frame_view.cc
deleted file mode 100644
index dd76c86..0000000
--- a/chrome/browser/views/frame/popup_non_client_frame_view.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/frame/popup_non_client_frame_view.h"
-
-#include "chrome/browser/views/tabs/base_tab_strip.h"
-#include "gfx/point.h"
-#include "gfx/rect.h"
-#include "gfx/size.h"
-
-#if defined(OS_LINUX)
-#include "views/window/hit_test.h"
-#endif
-
-gfx::Rect PopupNonClientFrameView::GetBoundsForClientView() const {
- return gfx::Rect(0, 0, width(), height());
-}
-
-bool PopupNonClientFrameView::AlwaysUseCustomFrame() const {
- return false;
-}
-
-bool PopupNonClientFrameView::AlwaysUseNativeFrame() const {
- return true;
-}
-
-gfx::Rect PopupNonClientFrameView::GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const {
- return client_bounds;
-}
-
-int PopupNonClientFrameView::NonClientHitTest(const gfx::Point& point) {
- return bounds().Contains(point) ? HTCLIENT : HTNOWHERE;
-}
-
-void PopupNonClientFrameView::GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask) {
-}
-
-void PopupNonClientFrameView::EnableClose(bool enable) {
-}
-
-void PopupNonClientFrameView::ResetWindowControls() {
-}
-
-gfx::Rect PopupNonClientFrameView::GetBoundsForTabStrip(
- BaseTabStrip* tabstrip) const {
- return gfx::Rect(0, 0, width(), tabstrip->GetPreferredHeight());
-}
-
-int PopupNonClientFrameView::GetHorizontalTabStripVerticalOffset(
- bool restored) const {
- return 0;
-}
-
-void PopupNonClientFrameView::UpdateThrobber(bool running) {
-}
diff --git a/chrome/browser/views/frame/popup_non_client_frame_view.h b/chrome/browser/views/frame/popup_non_client_frame_view.h
index 12982c9..4866d34 100644
--- a/chrome/browser/views/frame/popup_non_client_frame_view.h
+++ b/chrome/browser/views/frame/popup_non_client_frame_view.h
@@ -6,35 +6,8 @@
#define CHROME_BROWSER_VIEWS_FRAME_POPUP_NON_CLIENT_FRAME_VIEW_H_
#pragma once
-#include "chrome/browser/views/frame/browser_non_client_frame_view.h"
-
-class BaseTabStrip;
-
-// BrowserNonClientFrameView implementation for popups. We let the window
-// manager implementation render the decorations for popups, so this draws
-// nothing.
-class PopupNonClientFrameView : public BrowserNonClientFrameView {
- public:
- PopupNonClientFrameView() {}
-
- // NonClientFrameView:
- virtual gfx::Rect GetBoundsForClientView() const;
- virtual bool AlwaysUseCustomFrame() const;
- virtual bool AlwaysUseNativeFrame() const;
- virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
- virtual void EnableClose(bool enable);
- virtual void ResetWindowControls();
-
- // BrowserNonClientFrameView:
- virtual gfx::Rect GetBoundsForTabStrip(BaseTabStrip* tabstrip) const;
- virtual int GetHorizontalTabStripVerticalOffset(bool restored) const;
- virtual void UpdateThrobber(bool running);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(PopupNonClientFrameView);
-};
+#include "chrome/browser/ui/views/frame/popup_non_client_frame_view.h"
+// TODO(beng): remove this file once all includes have been updated.
#endif // CHROME_BROWSER_VIEWS_FRAME_POPUP_NON_CLIENT_FRAME_VIEW_H_
+