1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
10 #include "base/compiler_specific.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/browser/signin/signin_header_helper.h"
16 #include "chrome/browser/themes/theme_properties.h"
17 #include "chrome/browser/ui/views/frame/browser_frame.h"
18 #include "chrome/browser/ui/views/frame/browser_view.h"
19 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
20 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_specific.h"
21 #include "chrome/browser/ui/views/profiles/avatar_label.h"
22 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
23 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
24 #include "chrome/browser/ui/views/tab_icon_view.h"
25 #include "chrome/browser/ui/views/tabs/tab_strip.h"
26 #include "chrome/browser/ui/views/theme_image_mapper.h"
27 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
28 #include "chrome/common/pref_names.h"
29 #include "components/signin/core/common/profile_management_switches.h"
30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/web_contents.h"
32 #include "grit/chromium_strings.h"
33 #include "grit/generated_resources.h"
34 #include "grit/theme_resources.h"
35 #include "grit/ui_resources.h"
36 #include "ui/accessibility/ax_view_state.h"
37 #include "ui/base/hit_test.h"
38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/base/theme_provider.h"
41 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/font_list.h"
43 #include "ui/gfx/image/image.h"
44 #include "ui/gfx/image/image_skia.h"
45 #include "ui/gfx/path.h"
46 #include "ui/gfx/rect_conversions.h"
47 #include "ui/views/controls/button/image_button.h"
48 #include "ui/views/controls/image_view.h"
49 #include "ui/views/controls/label.h"
50 #include "ui/views/layout/layout_constants.h"
51 #include "ui/views/views_delegate.h"
52 #include "ui/views/widget/root_view.h"
53 #include "ui/views/window/frame_background.h"
54 #include "ui/views/window/window_shape.h"
57 #include "ui/views/controls/menu/menu_runner.h"
60 using content::WebContents;
64 // While resize areas on Windows are normally the same size as the window
65 // borders, our top area is shrunk by 1 px to make it easier to move the window
66 // around with our thinner top grabbable strip. (Incidentally, our side and
67 // bottom resize areas don't match the frame border thickness either -- they
68 // span the whole nonclient area, so there's no "dead zone" for the mouse.)
69 const int kTopResizeAdjust = 1;
71 // In the window corners, the resize areas don't actually expand bigger, but the
72 // 16 px at the end of each edge triggers diagonal resizing.
73 const int kResizeAreaCornerSize = 16;
75 // The content left/right images have a shadow built into them.
76 const int kContentEdgeShadowThickness = 2;
78 // The icon never shrinks below 16 px on a side.
79 const int kIconMinimumSize = 16;
81 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
82 // The number of pixels to move the frame background image upwards when using
83 // the GTK+ theme and the titlebar is condensed.
84 const int kGTKThemeCondensedFrameTopInset = 15;
89 ///////////////////////////////////////////////////////////////////////////////
90 // OpaqueBrowserFrameView, public:
92 OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
93 BrowserView* browser_view)
94 : BrowserNonClientFrameView(frame, browser_view),
95 layout_(new OpaqueBrowserFrameViewLayout(this)),
96 minimize_button_(NULL),
97 maximize_button_(NULL),
98 restore_button_(NULL),
102 frame_background_(new views::FrameBackground()) {
103 SetLayoutManager(layout_);
105 minimize_button_ = InitWindowCaptionButton(IDR_MINIMIZE,
108 IDR_MINIMIZE_BUTTON_MASK,
109 IDS_ACCNAME_MINIMIZE,
110 VIEW_ID_MINIMIZE_BUTTON);
111 maximize_button_ = InitWindowCaptionButton(IDR_MAXIMIZE,
114 IDR_MAXIMIZE_BUTTON_MASK,
115 IDS_ACCNAME_MAXIMIZE,
116 VIEW_ID_MAXIMIZE_BUTTON);
117 restore_button_ = InitWindowCaptionButton(IDR_RESTORE,
120 IDR_RESTORE_BUTTON_MASK,
122 VIEW_ID_RESTORE_BUTTON);
123 close_button_ = InitWindowCaptionButton(IDR_CLOSE,
126 IDR_CLOSE_BUTTON_MASK,
128 VIEW_ID_CLOSE_BUTTON);
130 // Initializing the TabIconView is expensive, so only do it if we need to.
131 if (browser_view->ShouldShowWindowIcon()) {
132 window_icon_ = new TabIconView(this, this);
133 window_icon_->set_is_light(true);
134 window_icon_->set_id(VIEW_ID_WINDOW_ICON);
135 AddChildView(window_icon_);
136 window_icon_->Update();
139 window_title_ = new views::Label(
140 browser_view->GetWindowTitle(),
141 gfx::FontList(BrowserFrame::GetTitleFontList()));
142 window_title_->SetVisible(browser_view->ShouldShowWindowTitle());
143 window_title_->SetEnabledColor(SK_ColorWHITE);
144 window_title_->set_subpixel_rendering_enabled(false);
145 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
146 window_title_->set_id(VIEW_ID_WINDOW_TITLE);
147 AddChildView(window_title_);
149 if (browser_view->IsRegularOrGuestSession() && switches::IsNewAvatarMenu())
150 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON);
154 if (!browser_view->IsOffTheRecord()) {
155 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
156 content::NotificationService::AllSources());
159 platform_observer_.reset(OpaqueBrowserFrameViewPlatformSpecific::Create(
160 this, layout_, browser_view->browser()->profile()));
163 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() {
166 ///////////////////////////////////////////////////////////////////////////////
167 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation:
169 gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip(
170 views::View* tabstrip) const {
174 return layout_->GetBoundsForTabStrip(tabstrip->GetPreferredSize(), width());
177 int OpaqueBrowserFrameView::GetTopInset() const {
178 return browser_view()->IsTabStripVisible() ?
179 layout_->GetTabStripInsetsTop(false) :
180 layout_->NonClientTopBorderHeight(false);
183 int OpaqueBrowserFrameView::GetThemeBackgroundXInset() const {
187 void OpaqueBrowserFrameView::UpdateThrobber(bool running) {
189 window_icon_->Update();
192 gfx::Size OpaqueBrowserFrameView::GetMinimumSize() const {
193 return layout_->GetMinimumSize(width());
196 ///////////////////////////////////////////////////////////////////////////////
197 // OpaqueBrowserFrameView, views::NonClientFrameView implementation:
199 gfx::Rect OpaqueBrowserFrameView::GetBoundsForClientView() const {
200 return layout_->client_view_bounds();
203 gfx::Rect OpaqueBrowserFrameView::GetWindowBoundsForClientBounds(
204 const gfx::Rect& client_bounds) const {
205 return layout_->GetWindowBoundsForClientBounds(client_bounds);
208 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
209 if (!bounds().Contains(point))
212 // See if the point is within the avatar menu button or within the avatar
214 if ((avatar_button() &&
215 avatar_button()->GetMirroredBounds().Contains(point)) ||
216 (avatar_label() && avatar_label()->GetMirroredBounds().Contains(point)) ||
217 (new_avatar_button() &&
218 new_avatar_button()->GetMirroredBounds().Contains(point)))
221 int frame_component = frame()->client_view()->NonClientHitTest(point);
223 // See if we're in the sysmenu region. We still have to check the tabstrip
224 // first so that clicks in a tab don't get treated as sysmenu clicks.
225 gfx::Rect sysmenu_rect(IconBounds());
226 // In maximized mode we extend the rect to the screen corner to take advantage
228 if (layout_->IsTitleBarCondensed())
229 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom());
230 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect));
231 if (sysmenu_rect.Contains(point))
232 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
234 if (frame_component != HTNOWHERE)
235 return frame_component;
237 // Then see if the point is within any of the window controls.
238 if (close_button_ && close_button_->visible() &&
239 close_button_->GetMirroredBounds().Contains(point))
241 if (restore_button_ && restore_button_->visible() &&
242 restore_button_->GetMirroredBounds().Contains(point))
244 if (maximize_button_ && maximize_button_->visible() &&
245 maximize_button_->GetMirroredBounds().Contains(point))
247 if (minimize_button_ && minimize_button_->visible() &&
248 minimize_button_->GetMirroredBounds().Contains(point))
251 views::WidgetDelegate* delegate = frame()->widget_delegate();
253 LOG(WARNING) << "delegate is NULL, returning safe default.";
256 int window_component = GetHTComponentForFrame(point, TopResizeHeight(),
257 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
258 delegate->CanResize());
259 // Fall back to the caption if no other component matches.
260 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
263 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size,
264 gfx::Path* window_mask) {
267 if (layout_->IsTitleBarCondensed() || frame()->IsFullscreen())
270 views::GetDefaultWindowMask(size, window_mask);
273 void OpaqueBrowserFrameView::ResetWindowControls() {
274 restore_button_->SetState(views::CustomButton::STATE_NORMAL);
275 minimize_button_->SetState(views::CustomButton::STATE_NORMAL);
276 maximize_button_->SetState(views::CustomButton::STATE_NORMAL);
277 // The close button isn't affected by this constraint.
280 void OpaqueBrowserFrameView::UpdateWindowIcon() {
281 window_icon_->SchedulePaint();
284 void OpaqueBrowserFrameView::UpdateWindowTitle() {
285 if (!frame()->IsFullscreen())
286 window_title_->SchedulePaint();
289 ///////////////////////////////////////////////////////////////////////////////
290 // OpaqueBrowserFrameView, views::View overrides:
292 bool OpaqueBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
293 if (!views::View::HitTestRect(rect)) {
294 // |rect| is outside OpaqueBrowserFrameView's bounds.
298 // If the rect is outside the bounds of the client area, claim it.
299 gfx::RectF rect_in_client_view_coords_f(rect);
300 View::ConvertRectToTarget(this, frame()->client_view(),
301 &rect_in_client_view_coords_f);
302 gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect(
303 rect_in_client_view_coords_f);
304 if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords))
307 // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in
308 // a non-tab portion.
309 TabStrip* tabstrip = browser_view()->tabstrip();
310 if (!tabstrip || !browser_view()->IsTabStripVisible())
313 gfx::RectF rect_in_tabstrip_coords_f(rect);
314 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
315 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
316 rect_in_tabstrip_coords_f);
317 if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) {
318 // |rect| is below the tabstrip.
322 if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) {
323 // Claim |rect| if it is in a non-tab portion of the tabstrip.
324 return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
327 // We claim |rect| because it is above the bottom of the tabstrip, but
328 // not in the tabstrip itself. In particular, the avatar label/button is left
329 // of the tabstrip and the window controls are right of the tabstrip.
333 void OpaqueBrowserFrameView::GetAccessibleState(
334 ui::AXViewState* state) {
335 state->role = ui::AX_ROLE_TITLE_BAR;
338 ///////////////////////////////////////////////////////////////////////////////
339 // OpaqueBrowserFrameView, views::ButtonListener implementation:
341 void OpaqueBrowserFrameView::ButtonPressed(views::Button* sender,
342 const ui::Event& event) {
343 if (sender == minimize_button_) {
345 } else if (sender == maximize_button_) {
347 } else if (sender == restore_button_) {
349 } else if (sender == close_button_) {
351 } else if (sender == new_avatar_button()) {
352 browser_view()->ShowAvatarBubbleFromAvatarButton(
353 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT,
354 signin::ManageAccountsParams());
358 void OpaqueBrowserFrameView::OnMenuButtonClicked(views::View* source,
359 const gfx::Point& point) {
360 #if defined(OS_LINUX)
361 views::MenuRunner menu_runner(frame()->GetSystemMenuModel());
362 ignore_result(menu_runner.RunMenuAt(browser_view()->GetWidget(),
364 window_icon_->GetBoundsInScreen(),
365 views::MENU_ANCHOR_TOPLEFT,
366 ui::MENU_SOURCE_MOUSE,
367 views::MenuRunner::HAS_MNEMONICS));
371 ///////////////////////////////////////////////////////////////////////////////
372 // OpaqueBrowserFrameView, TabIconView::TabContentsProvider implementation:
374 bool OpaqueBrowserFrameView::ShouldTabIconViewAnimate() const {
375 // This function is queried during the creation of the window as the
376 // TabIconView we host is initialized, so we need to NULL check the selected
377 // WebContents because in this condition there is not yet a selected tab.
378 WebContents* current_tab = browser_view()->GetActiveWebContents();
379 return current_tab ? current_tab->IsLoading() : false;
382 gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() {
383 views::WidgetDelegate* delegate = frame()->widget_delegate();
385 LOG(WARNING) << "delegate is NULL, returning safe default.";
386 return gfx::ImageSkia();
388 return delegate->GetWindowIcon();
391 ///////////////////////////////////////////////////////////////////////////////
392 // OpaqueBrowserFrameView, protected:
394 void OpaqueBrowserFrameView::Observe(
396 const content::NotificationSource& source,
397 const content::NotificationDetails& details) {
399 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
400 if (browser_view() ->IsRegularOrGuestSession() &&
401 switches::IsNewAvatarMenu()) {
402 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON);
408 NOTREACHED() << "Got a notification we didn't register for!";
413 ///////////////////////////////////////////////////////////////////////////////
414 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation:
416 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const {
417 views::WidgetDelegate* delegate = frame()->widget_delegate();
418 return ShouldShowWindowTitleBar() && delegate &&
419 delegate->ShouldShowWindowIcon();
422 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const {
423 // |delegate| may be NULL if called from callback of InputMethodChanged while
424 // a window is being destroyed.
425 // See more discussion at http://crosbug.com/8958
426 views::WidgetDelegate* delegate = frame()->widget_delegate();
427 return ShouldShowWindowTitleBar() && delegate &&
428 delegate->ShouldShowWindowTitle();
431 base::string16 OpaqueBrowserFrameView::GetWindowTitle() const {
432 return frame()->widget_delegate()->GetWindowTitle();
435 int OpaqueBrowserFrameView::GetIconSize() const {
437 // This metric scales up if either the titlebar height or the titlebar font
438 // size are increased.
439 return GetSystemMetrics(SM_CYSMICON);
441 return std::max(BrowserFrame::GetTitleFontList().GetHeight(),
446 bool OpaqueBrowserFrameView::ShouldLeaveOffsetNearTopBorder() const {
447 return frame()->ShouldLeaveOffsetNearTopBorder();
450 gfx::Size OpaqueBrowserFrameView::GetBrowserViewMinimumSize() const {
451 return browser_view()->GetMinimumSize();
454 bool OpaqueBrowserFrameView::ShouldShowCaptionButtons() const {
455 return ShouldShowWindowTitleBar();
458 bool OpaqueBrowserFrameView::ShouldShowAvatar() const {
459 return browser_view()->ShouldShowAvatar();
462 bool OpaqueBrowserFrameView::IsRegularOrGuestSession() const {
463 return browser_view()->IsRegularOrGuestSession();
466 gfx::ImageSkia OpaqueBrowserFrameView::GetOTRAvatarIcon() const {
467 return browser_view()->GetOTRAvatarIcon();
470 bool OpaqueBrowserFrameView::IsMaximized() const {
471 return frame()->IsMaximized();
474 bool OpaqueBrowserFrameView::IsMinimized() const {
475 return frame()->IsMinimized();
478 bool OpaqueBrowserFrameView::IsFullscreen() const {
479 return frame()->IsFullscreen();
482 bool OpaqueBrowserFrameView::IsTabStripVisible() const {
483 return browser_view()->IsTabStripVisible();
486 int OpaqueBrowserFrameView::GetTabStripHeight() const {
487 return browser_view()->GetTabStripHeight();
490 gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const {
491 gfx::Size s = browser_view()->tabstrip()->GetPreferredSize();
495 ///////////////////////////////////////////////////////////////////////////////
496 // OpaqueBrowserFrameView, views::View overrides:
498 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
499 if (frame()->IsFullscreen())
500 return; // Nothing is visible, so don't bother to paint.
502 if (layout_->IsTitleBarCondensed())
503 PaintMaximizedFrameBorder(canvas);
505 PaintRestoredFrameBorder(canvas);
507 // The window icon and title are painted by their respective views.
508 /* TODO(pkasting): If this window is active, we should also draw a drop
509 * shadow on the title. This is tricky, because we don't want to hardcode a
510 * shadow color (since we want to work with various themes), but we can't
511 * alpha-blend either (since the Windows text APIs don't really do this).
512 * So we'd need to sample the background color at the right location and
513 * synthesize a good shadow color. */
515 if (browser_view()->IsToolbarVisible())
516 PaintToolbarBackground(canvas);
517 if (!layout_->IsTitleBarCondensed())
518 PaintRestoredClientEdge(canvas);
521 ///////////////////////////////////////////////////////////////////////////////
522 // OpaqueBrowserFrameView, private:
524 views::ImageButton* OpaqueBrowserFrameView::InitWindowCaptionButton(
529 int accessibility_string_id,
531 views::ImageButton* button = new views::ImageButton(this);
532 ui::ThemeProvider* tp = frame()->GetThemeProvider();
533 button->SetImage(views::CustomButton::STATE_NORMAL,
534 tp->GetImageSkiaNamed(normal_image_id));
535 button->SetImage(views::CustomButton::STATE_HOVERED,
536 tp->GetImageSkiaNamed(hot_image_id));
537 button->SetImage(views::CustomButton::STATE_PRESSED,
538 tp->GetImageSkiaNamed(pushed_image_id));
539 if (browser_view()->IsBrowserTypeNormal()) {
540 button->SetBackground(
541 tp->GetColor(ThemeProperties::COLOR_BUTTON_BACKGROUND),
542 tp->GetImageSkiaNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND),
543 tp->GetImageSkiaNamed(mask_image_id));
545 button->SetAccessibleName(
546 l10n_util::GetStringUTF16(accessibility_string_id));
547 button->set_id(view_id);
548 AddChildView(button);
552 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
553 return layout_->FrameBorderThickness(restored);
556 int OpaqueBrowserFrameView::TopResizeHeight() const {
557 return FrameBorderThickness(false) - kTopResizeAdjust;
560 int OpaqueBrowserFrameView::NonClientBorderThickness() const {
561 return layout_->NonClientBorderThickness();
564 gfx::Rect OpaqueBrowserFrameView::IconBounds() const {
565 return layout_->IconBounds();
568 bool OpaqueBrowserFrameView::ShouldShowWindowTitleBar() const {
569 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
570 // Do not show the custom title bar if the system title bar option is enabled.
571 if (!frame()->UseCustomFrame())
575 // Do not show caption buttons if the window manager is forcefully providing a
576 // title bar (e.g., in Ubuntu Unity, if the window is maximized).
577 if (!views::ViewsDelegate::views_delegate)
579 return !views::ViewsDelegate::views_delegate->WindowManagerProvidesTitleBar(
583 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
584 frame_background_->set_frame_color(GetFrameColor());
585 frame_background_->set_theme_image(GetFrameImage());
586 frame_background_->set_theme_overlay_image(GetFrameOverlayImage());
587 frame_background_->set_top_area_height(GetTopAreaHeight());
589 ui::ThemeProvider* tp = GetThemeProvider();
590 frame_background_->SetSideImages(
591 tp->GetImageSkiaNamed(IDR_WINDOW_LEFT_SIDE),
592 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_CENTER),
593 tp->GetImageSkiaNamed(IDR_WINDOW_RIGHT_SIDE),
594 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_CENTER));
595 frame_background_->SetCornerImages(
596 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_LEFT_CORNER),
597 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_RIGHT_CORNER),
598 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER),
599 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER));
600 frame_background_->PaintRestored(canvas, this);
602 // Note: When we don't have a toolbar, we need to draw some kind of bottom
603 // edge here. Because the App Window graphics we use for this have an
604 // attached client edge and their sizing algorithm is a little involved, we do
605 // all this in PaintRestoredClientEdge().
608 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
609 ui::ThemeProvider* tp = GetThemeProvider();
610 frame_background_->set_frame_color(GetFrameColor());
611 frame_background_->set_theme_image(GetFrameImage());
612 frame_background_->set_theme_overlay_image(GetFrameOverlayImage());
613 frame_background_->set_top_area_height(GetTopAreaHeight());
614 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
615 // The window manager typically shows a gradient in the native title bar (when
616 // the system title bar pref is set, or when maximized on Ubuntu). Hide the
617 // gradient in the tab strip (by shifting it up vertically) to avoid a
618 // double-gradient effect.
619 if (tp->UsingSystemTheme())
620 frame_background_->set_maximized_top_inset(kGTKThemeCondensedFrameTopInset);
623 frame_background_->PaintMaximized(canvas, this);
625 // TODO(jamescook): Migrate this into FrameBackground.
626 if (!browser_view()->IsToolbarVisible()) {
627 // There's no toolbar to edge the frame border, so we need to draw a bottom
628 // edge. The graphic we use for this has a built in client edge, so we clip
629 // it off the bottom.
630 gfx::ImageSkia* top_center = tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER);
631 int edge_height = top_center->height() - kClientEdgeThickness;
632 canvas->TileImageInt(*top_center, 0,
633 frame()->client_view()->y() - edge_height, width(), edge_height);
637 void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
638 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
639 if (toolbar_bounds.IsEmpty())
641 gfx::Point toolbar_origin(toolbar_bounds.origin());
642 ConvertPointToTarget(browser_view(), this, &toolbar_origin);
643 toolbar_bounds.set_origin(toolbar_origin);
645 int x = toolbar_bounds.x();
646 int w = toolbar_bounds.width();
647 int y = toolbar_bounds.y();
648 int h = toolbar_bounds.height();
650 // Gross hack: We split the toolbar images into two pieces, since sometimes
651 // (popup mode) the toolbar isn't tall enough to show the whole image. The
652 // split happens between the top shadow section and the bottom gradient
653 // section so that we never break the gradient.
654 int split_point = kFrameShadowThickness * 2;
655 int bottom_y = y + split_point;
656 ui::ThemeProvider* tp = GetThemeProvider();
657 gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(
658 IDR_CONTENT_TOP_LEFT_CORNER);
659 int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point;
661 // Split our canvas out so we can mask out the corners of the toolbar
662 // without masking out the frame.
663 canvas->SaveLayerAlpha(
664 255, gfx::Rect(x - kClientEdgeThickness, y, w + kClientEdgeThickness * 3,
667 // Paint the bottom rect.
668 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
669 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
671 // Tile the toolbar image starting at the frame edge on the left and where the
672 // horizontal tabstrip is (or would be) on the top.
673 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
674 canvas->TileImageInt(*theme_toolbar,
675 x + GetThemeBackgroundXInset(),
676 bottom_y - GetTopInset(),
677 x, bottom_y, w, theme_toolbar->height());
679 // Draw rounded corners for the tab.
680 gfx::ImageSkia* toolbar_left_mask =
681 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
682 gfx::ImageSkia* toolbar_right_mask =
683 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
685 // We mask out the corners by using the DestinationIn transfer mode,
686 // which keeps the RGB pixels from the destination and the alpha from
689 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
691 // Mask the left edge.
692 int left_x = x - kContentEdgeShadowThickness;
693 canvas->DrawImageInt(*toolbar_left_mask, 0, 0, toolbar_left_mask->width(),
694 split_point, left_x, y, toolbar_left_mask->width(),
695 split_point, false, paint);
696 canvas->DrawImageInt(*toolbar_left_mask, 0,
697 toolbar_left_mask->height() - bottom_edge_height,
698 toolbar_left_mask->width(), bottom_edge_height, left_x, bottom_y,
699 toolbar_left_mask->width(), bottom_edge_height, false, paint);
701 // Mask the right edge.
703 x + w - toolbar_right_mask->width() + kContentEdgeShadowThickness;
704 canvas->DrawImageInt(*toolbar_right_mask, 0, 0, toolbar_right_mask->width(),
705 split_point, right_x, y, toolbar_right_mask->width(),
706 split_point, false, paint);
707 canvas->DrawImageInt(*toolbar_right_mask, 0,
708 toolbar_right_mask->height() - bottom_edge_height,
709 toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y,
710 toolbar_right_mask->width(), bottom_edge_height, false, paint);
713 canvas->DrawImageInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point,
714 left_x, y, toolbar_left->width(), split_point, false);
715 canvas->DrawImageInt(*toolbar_left, 0,
716 toolbar_left->height() - bottom_edge_height, toolbar_left->width(),
717 bottom_edge_height, left_x, bottom_y, toolbar_left->width(),
718 bottom_edge_height, false);
720 gfx::ImageSkia* toolbar_center =
721 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
722 canvas->TileImageInt(*toolbar_center, 0, 0, left_x + toolbar_left->width(),
723 y, right_x - (left_x + toolbar_left->width()),
726 gfx::ImageSkia* toolbar_right = tp->GetImageSkiaNamed(
727 IDR_CONTENT_TOP_RIGHT_CORNER);
728 canvas->DrawImageInt(*toolbar_right, 0, 0, toolbar_right->width(),
729 split_point, right_x, y, toolbar_right->width(), split_point, false);
730 canvas->DrawImageInt(*toolbar_right, 0,
731 toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
732 bottom_edge_height, right_x, bottom_y, toolbar_right->width(),
733 bottom_edge_height, false);
735 // Draw the content/toolbar separator.
737 gfx::Rect(x + kClientEdgeThickness,
738 toolbar_bounds.bottom() - kClientEdgeThickness,
739 w - (2 * kClientEdgeThickness),
740 kClientEdgeThickness),
741 ThemeProperties::GetDefaultColor(
742 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
745 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
746 ui::ThemeProvider* tp = GetThemeProvider();
747 int client_area_top = frame()->client_view()->y();
748 int image_top = client_area_top;
750 gfx::Rect client_area_bounds =
751 layout_->CalculateClientAreaBounds(width(), height());
752 SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
754 if (browser_view()->IsToolbarVisible()) {
755 // The client edge images always start below the toolbar corner images. The
756 // client edge filled rects start there or at the bottom of the toolbar,
757 // whichever is shorter.
758 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
760 gfx::ImageSkia* content_top_left_corner =
761 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
762 // TODO(oshima): Sanity checks for crbug.com/374273. Remove when it's fixed.
763 CHECK(content_top_left_corner);
764 CHECK(!content_top_left_corner->isNull());
766 image_top += toolbar_bounds.y() + content_top_left_corner->height();
767 client_area_top = std::min(image_top,
768 client_area_top + toolbar_bounds.bottom() - kClientEdgeThickness);
769 } else if (!browser_view()->IsTabStripVisible()) {
770 // The toolbar isn't going to draw a client edge for us, so draw one
772 gfx::ImageSkia* top_left = tp->GetImageSkiaNamed(IDR_APP_TOP_LEFT);
773 gfx::ImageSkia* top_center = tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER);
774 gfx::ImageSkia* top_right = tp->GetImageSkiaNamed(IDR_APP_TOP_RIGHT);
775 int top_edge_y = client_area_top - top_center->height();
776 int height = client_area_top - top_edge_y;
778 canvas->DrawImageInt(*top_left, 0, 0, top_left->width(), height,
779 client_area_bounds.x() - top_left->width(), top_edge_y,
780 top_left->width(), height, false);
781 canvas->TileImageInt(*top_center, 0, 0, client_area_bounds.x(), top_edge_y,
782 client_area_bounds.width(), std::min(height, top_center->height()));
783 canvas->DrawImageInt(*top_right, 0, 0, top_right->width(), height,
784 client_area_bounds.right(), top_edge_y,
785 top_right->width(), height, false);
787 // Draw the toolbar color across the top edge.
788 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
789 client_area_top - kClientEdgeThickness,
790 client_area_bounds.width() + (2 * kClientEdgeThickness),
791 kClientEdgeThickness), toolbar_color);
794 int client_area_bottom =
795 std::max(client_area_top, height() - NonClientBorderThickness());
796 int image_height = client_area_bottom - image_top;
798 // Draw the client edge images.
799 gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
800 canvas->TileImageInt(*right, client_area_bounds.right(), image_top,
801 right->width(), image_height);
802 canvas->DrawImageInt(
803 *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
804 client_area_bounds.right(), client_area_bottom);
805 gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
806 canvas->TileImageInt(*bottom, client_area_bounds.x(),
807 client_area_bottom, client_area_bounds.width(),
809 gfx::ImageSkia* bottom_left =
810 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
811 canvas->DrawImageInt(*bottom_left,
812 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
813 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
814 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
815 image_top, left->width(), image_height);
817 // Draw the toolbar color so that the client edges show the right color even
818 // where not covered by the toolbar image. NOTE: We do this after drawing the
819 // images because the images are meant to alpha-blend atop the frame whereas
820 // these rects are meant to be fully opaque, without anything overlaid.
821 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
822 client_area_top, kClientEdgeThickness,
823 client_area_bottom + kClientEdgeThickness - client_area_top),
825 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom,
826 client_area_bounds.width(), kClientEdgeThickness),
828 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top,
829 kClientEdgeThickness,
830 client_area_bottom + kClientEdgeThickness - client_area_top),
834 SkColor OpaqueBrowserFrameView::GetFrameColor() const {
835 bool is_incognito = browser_view()->IsOffTheRecord();
836 ThemeProperties::OverwritableByUserThemeProperty color_id;
837 if (ShouldPaintAsActive()) {
838 color_id = is_incognito ?
839 ThemeProperties::COLOR_FRAME_INCOGNITO :
840 ThemeProperties::COLOR_FRAME;
842 color_id = is_incognito ?
843 ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE :
844 ThemeProperties::COLOR_FRAME_INACTIVE;
847 if (browser_view()->IsBrowserTypeNormal() ||
848 platform_observer_->IsUsingSystemTheme()) {
849 return GetThemeProvider()->GetColor(color_id);
852 // Never theme app and popup windows unless the |platform_observer_|
853 // requested an override.
854 return ThemeProperties::GetDefaultColor(color_id);
857 gfx::ImageSkia* OpaqueBrowserFrameView::GetFrameImage() const {
858 bool is_incognito = browser_view()->IsOffTheRecord();
860 if (browser_view()->IsBrowserTypeNormal()) {
861 if (ShouldPaintAsActive()) {
862 resource_id = is_incognito ?
863 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME;
865 resource_id = is_incognito ?
866 IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE;
868 return GetThemeProvider()->GetImageSkiaNamed(resource_id);
870 if (ShouldPaintAsActive()) {
871 resource_id = is_incognito ?
872 IDR_THEME_FRAME_INCOGNITO : IDR_FRAME;
874 resource_id = is_incognito ?
875 IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE;
878 if (platform_observer_->IsUsingSystemTheme()) {
879 // We want to use theme images provided by the system theme when enabled,
880 // even if we are an app or popup window.
881 return GetThemeProvider()->GetImageSkiaNamed(resource_id);
884 // Otherwise, never theme app and popup windows.
885 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
886 return rb.GetImageSkiaNamed(chrome::MapThemeImage(
887 chrome::GetHostDesktopTypeForNativeWindow(
888 browser_view()->GetNativeWindow()),
892 gfx::ImageSkia* OpaqueBrowserFrameView::GetFrameOverlayImage() const {
893 ui::ThemeProvider* tp = GetThemeProvider();
894 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) &&
895 browser_view()->IsBrowserTypeNormal() &&
896 !browser_view()->IsOffTheRecord()) {
897 return tp->GetImageSkiaNamed(ShouldPaintAsActive() ?
898 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE);
903 int OpaqueBrowserFrameView::GetTopAreaHeight() const {
904 gfx::ImageSkia* frame_image = GetFrameImage();
905 int top_area_height = frame_image->height();
906 if (browser_view()->IsTabStripVisible()) {
907 top_area_height = std::max(top_area_height,
908 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom());
910 return top_area_height;