Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / opaque_browser_frame_view.cc
blobe155e51c47ea007750f8692a2b0b897033229e4a
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"
7 #include <algorithm>
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/profiler/scoped_tracker.h"
13 #include "base/strings/utf_string_conversions.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_menu_button.h"
22 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
23 #include "chrome/browser/ui/views/tab_icon_view.h"
24 #include "chrome/browser/ui/views/tabs/tab_strip.h"
25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
26 #include "chrome/grit/generated_resources.h"
27 #include "components/signin/core/common/profile_management_switches.h"
28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/web_contents.h"
30 #include "grit/theme_resources.h"
31 #include "ui/accessibility/ax_view_state.h"
32 #include "ui/base/hit_test.h"
33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/base/theme_provider.h"
36 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/font_list.h"
38 #include "ui/gfx/geometry/rect_conversions.h"
39 #include "ui/gfx/image/image.h"
40 #include "ui/gfx/image/image_skia.h"
41 #include "ui/gfx/path.h"
42 #include "ui/resources/grit/ui_resources.h"
43 #include "ui/views/controls/button/image_button.h"
44 #include "ui/views/controls/image_view.h"
45 #include "ui/views/controls/label.h"
46 #include "ui/views/layout/layout_constants.h"
47 #include "ui/views/views_delegate.h"
48 #include "ui/views/widget/root_view.h"
49 #include "ui/views/window/frame_background.h"
50 #include "ui/views/window/window_shape.h"
52 #if defined(ENABLE_SUPERVISED_USERS)
53 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h"
54 #endif
56 #if defined(OS_LINUX)
57 #include "ui/views/controls/menu/menu_runner.h"
58 #endif
60 using content::WebContents;
62 namespace {
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;
85 #endif
87 } // namespace
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_(nullptr),
97 maximize_button_(nullptr),
98 restore_button_(nullptr),
99 close_button_(nullptr),
100 window_icon_(nullptr),
101 window_title_(nullptr),
102 frame_background_(new views::FrameBackground()) {
103 SetLayoutManager(layout_);
105 minimize_button_ = InitWindowCaptionButton(IDR_MINIMIZE,
106 IDR_MINIMIZE_H,
107 IDR_MINIMIZE_P,
108 IDR_MINIMIZE_BUTTON_MASK,
109 IDS_ACCNAME_MINIMIZE,
110 VIEW_ID_MINIMIZE_BUTTON);
111 maximize_button_ = InitWindowCaptionButton(IDR_MAXIMIZE,
112 IDR_MAXIMIZE_H,
113 IDR_MAXIMIZE_P,
114 IDR_MAXIMIZE_BUTTON_MASK,
115 IDS_ACCNAME_MAXIMIZE,
116 VIEW_ID_MAXIMIZE_BUTTON);
117 restore_button_ = InitWindowCaptionButton(IDR_RESTORE,
118 IDR_RESTORE_H,
119 IDR_RESTORE_P,
120 IDR_RESTORE_BUTTON_MASK,
121 IDS_ACCNAME_RESTORE,
122 VIEW_ID_RESTORE_BUTTON);
123 close_button_ = InitWindowCaptionButton(IDR_CLOSE,
124 IDR_CLOSE_H,
125 IDR_CLOSE_P,
126 IDR_CLOSE_BUTTON_MASK,
127 IDS_ACCNAME_CLOSE,
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_->SetSubpixelRenderingEnabled(false);
145 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
146 window_title_->set_id(VIEW_ID_WINDOW_TITLE);
147 AddChildView(window_title_);
149 UpdateAvatar();
151 platform_observer_.reset(OpaqueBrowserFrameViewPlatformSpecific::Create(
152 this, layout_, browser_view->browser()->profile()));
155 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() {
158 ///////////////////////////////////////////////////////////////////////////////
159 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation:
161 gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip(
162 views::View* tabstrip) const {
163 if (!tabstrip)
164 return gfx::Rect();
166 return layout_->GetBoundsForTabStrip(tabstrip->GetPreferredSize(), width());
169 int OpaqueBrowserFrameView::GetTopInset() const {
170 return browser_view()->IsTabStripVisible() ?
171 layout_->GetTabStripInsetsTop(false) :
172 layout_->NonClientTopBorderHeight(false);
175 int OpaqueBrowserFrameView::GetThemeBackgroundXInset() const {
176 return 0;
179 void OpaqueBrowserFrameView::UpdateThrobber(bool running) {
180 if (window_icon_)
181 window_icon_->Update();
184 gfx::Size OpaqueBrowserFrameView::GetMinimumSize() const {
185 return layout_->GetMinimumSize(width());
188 ///////////////////////////////////////////////////////////////////////////////
189 // OpaqueBrowserFrameView, views::NonClientFrameView implementation:
191 gfx::Rect OpaqueBrowserFrameView::GetBoundsForClientView() const {
192 return layout_->client_view_bounds();
195 gfx::Rect OpaqueBrowserFrameView::GetWindowBoundsForClientBounds(
196 const gfx::Rect& client_bounds) const {
197 return layout_->GetWindowBoundsForClientBounds(client_bounds);
200 bool OpaqueBrowserFrameView::IsWithinAvatarMenuButtons(
201 const gfx::Point& point) const {
202 if (avatar_button() &&
203 avatar_button()->GetMirroredBounds().Contains(point)) {
204 return true;
206 if (new_avatar_button() &&
207 new_avatar_button()->GetMirroredBounds().Contains(point)) {
208 return true;
211 return false;
214 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
215 if (!bounds().Contains(point))
216 return HTNOWHERE;
218 // See if the point is within the avatar menu button.
219 if (IsWithinAvatarMenuButtons(point))
220 return HTCLIENT;
221 #if defined(ENABLE_SUPERVISED_USERS)
222 // ...or within the avatar label, if it's a supervised user.
223 if ((supervised_user_avatar_label() &&
224 supervised_user_avatar_label()->GetMirroredBounds().Contains(point)))
225 return HTCLIENT;
226 #endif
228 int frame_component = frame()->client_view()->NonClientHitTest(point);
230 // See if we're in the sysmenu region. We still have to check the tabstrip
231 // first so that clicks in a tab don't get treated as sysmenu clicks.
232 gfx::Rect sysmenu_rect(IconBounds());
233 // In maximized mode we extend the rect to the screen corner to take advantage
234 // of Fitts' Law.
235 if (layout_->IsTitleBarCondensed())
236 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom());
237 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect));
238 if (sysmenu_rect.Contains(point))
239 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
241 if (frame_component != HTNOWHERE)
242 return frame_component;
244 // Then see if the point is within any of the window controls.
245 if (close_button_ && close_button_->visible() &&
246 close_button_->GetMirroredBounds().Contains(point))
247 return HTCLOSE;
248 if (restore_button_ && restore_button_->visible() &&
249 restore_button_->GetMirroredBounds().Contains(point))
250 return HTMAXBUTTON;
251 if (maximize_button_ && maximize_button_->visible() &&
252 maximize_button_->GetMirroredBounds().Contains(point))
253 return HTMAXBUTTON;
254 if (minimize_button_ && minimize_button_->visible() &&
255 minimize_button_->GetMirroredBounds().Contains(point))
256 return HTMINBUTTON;
258 views::WidgetDelegate* delegate = frame()->widget_delegate();
259 if (!delegate) {
260 LOG(WARNING) << "delegate is null, returning safe default.";
261 return HTCAPTION;
263 int window_component = GetHTComponentForFrame(point, TopResizeHeight(),
264 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
265 delegate->CanResize());
266 // Fall back to the caption if no other component matches.
267 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
270 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size,
271 gfx::Path* window_mask) {
272 DCHECK(window_mask);
274 if (layout_->IsTitleBarCondensed() || frame()->IsFullscreen())
275 return;
277 views::GetDefaultWindowMask(size, window_mask);
280 void OpaqueBrowserFrameView::ResetWindowControls() {
281 restore_button_->SetState(views::CustomButton::STATE_NORMAL);
282 minimize_button_->SetState(views::CustomButton::STATE_NORMAL);
283 maximize_button_->SetState(views::CustomButton::STATE_NORMAL);
284 // The close button isn't affected by this constraint.
287 void OpaqueBrowserFrameView::UpdateWindowIcon() {
288 if (window_icon_)
289 window_icon_->SchedulePaint();
292 void OpaqueBrowserFrameView::UpdateWindowTitle() {
293 if (!frame()->IsFullscreen())
294 window_title_->SchedulePaint();
297 void OpaqueBrowserFrameView::SizeConstraintsChanged() {
300 ///////////////////////////////////////////////////////////////////////////////
301 // OpaqueBrowserFrameView, views::View overrides:
303 void OpaqueBrowserFrameView::GetAccessibleState(
304 ui::AXViewState* state) {
305 state->role = ui::AX_ROLE_TITLE_BAR;
308 ///////////////////////////////////////////////////////////////////////////////
309 // OpaqueBrowserFrameView, views::ButtonListener implementation:
311 void OpaqueBrowserFrameView::ButtonPressed(views::Button* sender,
312 const ui::Event& event) {
313 if (sender == minimize_button_) {
314 frame()->Minimize();
315 } else if (sender == maximize_button_) {
316 frame()->Maximize();
317 } else if (sender == restore_button_) {
318 frame()->Restore();
319 } else if (sender == close_button_) {
320 frame()->Close();
321 } else if (sender == new_avatar_button()) {
322 BrowserWindow::AvatarBubbleMode mode =
323 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT;
324 if (event.IsMouseEvent() &&
325 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) {
326 mode = BrowserWindow::AVATAR_BUBBLE_MODE_FAST_USER_SWITCH;
328 browser_view()->ShowAvatarBubbleFromAvatarButton(
329 mode,
330 signin::ManageAccountsParams());
334 void OpaqueBrowserFrameView::OnMenuButtonClicked(views::View* source,
335 const gfx::Point& point) {
336 #if defined(OS_LINUX)
337 views::MenuRunner menu_runner(frame()->GetSystemMenuModel(),
338 views::MenuRunner::HAS_MNEMONICS);
339 ignore_result(menu_runner.RunMenuAt(browser_view()->GetWidget(),
340 window_icon_,
341 window_icon_->GetBoundsInScreen(),
342 views::MENU_ANCHOR_TOPLEFT,
343 ui::MENU_SOURCE_MOUSE));
344 #endif
347 ///////////////////////////////////////////////////////////////////////////////
348 // OpaqueBrowserFrameView, TabIconView::TabContentsProvider implementation:
350 bool OpaqueBrowserFrameView::ShouldTabIconViewAnimate() const {
351 // This function is queried during the creation of the window as the
352 // TabIconView we host is initialized, so we need to null check the selected
353 // WebContents because in this condition there is not yet a selected tab.
354 WebContents* current_tab = browser_view()->GetActiveWebContents();
355 return current_tab ? current_tab->IsLoading() : false;
358 gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() {
359 views::WidgetDelegate* delegate = frame()->widget_delegate();
360 if (!delegate) {
361 LOG(WARNING) << "delegate is null, returning safe default.";
362 return gfx::ImageSkia();
364 return delegate->GetWindowIcon();
367 ///////////////////////////////////////////////////////////////////////////////
368 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation:
370 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const {
371 views::WidgetDelegate* delegate = frame()->widget_delegate();
372 return ShouldShowWindowTitleBar() && delegate &&
373 delegate->ShouldShowWindowIcon();
376 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const {
377 // |delegate| may be null if called from callback of InputMethodChanged while
378 // a window is being destroyed.
379 // See more discussion at http://crosbug.com/8958
380 views::WidgetDelegate* delegate = frame()->widget_delegate();
381 return ShouldShowWindowTitleBar() && delegate &&
382 delegate->ShouldShowWindowTitle();
385 base::string16 OpaqueBrowserFrameView::GetWindowTitle() const {
386 return frame()->widget_delegate()->GetWindowTitle();
389 int OpaqueBrowserFrameView::GetIconSize() const {
390 #if defined(OS_WIN)
391 // This metric scales up if either the titlebar height or the titlebar font
392 // size are increased.
393 return GetSystemMetrics(SM_CYSMICON);
394 #else
395 return std::max(BrowserFrame::GetTitleFontList().GetHeight(),
396 kIconMinimumSize);
397 #endif
400 bool OpaqueBrowserFrameView::ShouldLeaveOffsetNearTopBorder() const {
401 return frame()->ShouldLeaveOffsetNearTopBorder();
404 gfx::Size OpaqueBrowserFrameView::GetBrowserViewMinimumSize() const {
405 return browser_view()->GetMinimumSize();
408 bool OpaqueBrowserFrameView::ShouldShowCaptionButtons() const {
409 return ShouldShowWindowTitleBar();
412 bool OpaqueBrowserFrameView::ShouldShowAvatar() const {
413 return browser_view()->ShouldShowAvatar();
416 bool OpaqueBrowserFrameView::IsRegularOrGuestSession() const {
417 return browser_view()->IsRegularOrGuestSession();
420 gfx::ImageSkia OpaqueBrowserFrameView::GetOTRAvatarIcon() const {
421 return browser_view()->GetOTRAvatarIcon();
424 bool OpaqueBrowserFrameView::IsMaximized() const {
425 return frame()->IsMaximized();
428 bool OpaqueBrowserFrameView::IsMinimized() const {
429 return frame()->IsMinimized();
432 bool OpaqueBrowserFrameView::IsFullscreen() const {
433 return frame()->IsFullscreen();
436 bool OpaqueBrowserFrameView::IsTabStripVisible() const {
437 return browser_view()->IsTabStripVisible();
440 int OpaqueBrowserFrameView::GetTabStripHeight() const {
441 return browser_view()->GetTabStripHeight();
444 gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const {
445 gfx::Size s = browser_view()->tabstrip()->GetPreferredSize();
446 return s;
449 ///////////////////////////////////////////////////////////////////////////////
450 // OpaqueBrowserFrameView, protected:
452 // views::View:
453 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
454 if (frame()->IsFullscreen())
455 return; // Nothing is visible, so don't bother to paint.
457 if (layout_->IsTitleBarCondensed())
458 PaintMaximizedFrameBorder(canvas);
459 else
460 PaintRestoredFrameBorder(canvas);
462 // The window icon and title are painted by their respective views.
463 /* TODO(pkasting): If this window is active, we should also draw a drop
464 * shadow on the title. This is tricky, because we don't want to hardcode a
465 * shadow color (since we want to work with various themes), but we can't
466 * alpha-blend either (since the Windows text APIs don't really do this).
467 * So we'd need to sample the background color at the right location and
468 * synthesize a good shadow color. */
470 if (browser_view()->IsToolbarVisible())
471 PaintToolbarBackground(canvas);
472 if (!layout_->IsTitleBarCondensed())
473 PaintRestoredClientEdge(canvas);
476 // BrowserNonClientFrameView:
477 bool OpaqueBrowserFrameView::ShouldPaintAsThemed() const {
478 // Theme app and popup windows if |platform_observer_| wants it.
479 return browser_view()->IsBrowserTypeNormal() ||
480 platform_observer_->IsUsingSystemTheme();
483 void OpaqueBrowserFrameView::UpdateNewAvatarButtonImpl() {
484 UpdateNewAvatarButton(this, NewAvatarButton::THEMED_BUTTON);
487 ///////////////////////////////////////////////////////////////////////////////
488 // OpaqueBrowserFrameView, private:
490 // views::NonClientFrameView:
491 bool OpaqueBrowserFrameView::DoesIntersectRect(const views::View* target,
492 const gfx::Rect& rect) const {
493 CHECK_EQ(target, this);
494 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) {
495 // |rect| is outside OpaqueBrowserFrameView's bounds.
496 return false;
499 // If the rect is outside the bounds of the client area, claim it.
500 gfx::RectF rect_in_client_view_coords_f(rect);
501 View::ConvertRectToTarget(this, frame()->client_view(),
502 &rect_in_client_view_coords_f);
503 gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect(
504 rect_in_client_view_coords_f);
505 if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords))
506 return true;
508 // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in
509 // a non-tab portion.
510 TabStrip* tabstrip = browser_view()->tabstrip();
511 if (!tabstrip || !browser_view()->IsTabStripVisible())
512 return false;
514 gfx::RectF rect_in_tabstrip_coords_f(rect);
515 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
516 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
517 rect_in_tabstrip_coords_f);
518 if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) {
519 // |rect| is below the tabstrip.
520 return false;
523 if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) {
524 // Claim |rect| if it is in a non-tab portion of the tabstrip.
525 return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
528 // We claim |rect| because it is above the bottom of the tabstrip, but
529 // not in the tabstrip itself. In particular, the avatar label/button is left
530 // of the tabstrip and the window controls are right of the tabstrip.
531 return true;
534 views::ImageButton* OpaqueBrowserFrameView::InitWindowCaptionButton(
535 int normal_image_id,
536 int hot_image_id,
537 int pushed_image_id,
538 int mask_image_id,
539 int accessibility_string_id,
540 ViewID view_id) {
541 views::ImageButton* button = new views::ImageButton(this);
542 ui::ThemeProvider* tp = frame()->GetThemeProvider();
543 button->SetImage(views::CustomButton::STATE_NORMAL,
544 tp->GetImageSkiaNamed(normal_image_id));
545 button->SetImage(views::CustomButton::STATE_HOVERED,
546 tp->GetImageSkiaNamed(hot_image_id));
547 button->SetImage(views::CustomButton::STATE_PRESSED,
548 tp->GetImageSkiaNamed(pushed_image_id));
549 if (browser_view()->IsBrowserTypeNormal()) {
550 button->SetBackground(
551 tp->GetColor(ThemeProperties::COLOR_BUTTON_BACKGROUND),
552 tp->GetImageSkiaNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND),
553 tp->GetImageSkiaNamed(mask_image_id));
555 button->SetAccessibleName(
556 l10n_util::GetStringUTF16(accessibility_string_id));
557 button->set_id(view_id);
558 AddChildView(button);
559 return button;
562 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
563 return layout_->FrameBorderThickness(restored);
566 int OpaqueBrowserFrameView::TopResizeHeight() const {
567 return FrameBorderThickness(false) - kTopResizeAdjust;
570 int OpaqueBrowserFrameView::NonClientBorderThickness() const {
571 return layout_->NonClientBorderThickness();
574 gfx::Rect OpaqueBrowserFrameView::IconBounds() const {
575 return layout_->IconBounds();
578 bool OpaqueBrowserFrameView::ShouldShowWindowTitleBar() const {
579 // Do not show the custom title bar if the system title bar option is enabled.
580 if (!frame()->UseCustomFrame())
581 return false;
583 // Do not show caption buttons if the window manager is forcefully providing a
584 // title bar (e.g., in Ubuntu Unity, if the window is maximized).
585 if (!views::ViewsDelegate::views_delegate)
586 return true;
587 return !views::ViewsDelegate::views_delegate->WindowManagerProvidesTitleBar(
588 IsMaximized());
591 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
592 frame_background_->set_frame_color(GetFrameColor());
593 frame_background_->set_theme_image(GetFrameImage());
594 frame_background_->set_theme_overlay_image(GetFrameOverlayImage());
595 frame_background_->set_top_area_height(GetTopAreaHeight());
597 ui::ThemeProvider* tp = GetThemeProvider();
598 frame_background_->SetSideImages(
599 tp->GetImageSkiaNamed(IDR_WINDOW_LEFT_SIDE),
600 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_CENTER),
601 tp->GetImageSkiaNamed(IDR_WINDOW_RIGHT_SIDE),
602 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_CENTER));
603 frame_background_->SetCornerImages(
604 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_LEFT_CORNER),
605 tp->GetImageSkiaNamed(IDR_WINDOW_TOP_RIGHT_CORNER),
606 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER),
607 tp->GetImageSkiaNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER));
608 frame_background_->PaintRestored(canvas, this);
610 // Note: When we don't have a toolbar, we need to draw some kind of bottom
611 // edge here. Because the App Window graphics we use for this have an
612 // attached client edge and their sizing algorithm is a little involved, we do
613 // all this in PaintRestoredClientEdge().
616 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
617 ui::ThemeProvider* tp = GetThemeProvider();
618 frame_background_->set_frame_color(GetFrameColor());
619 frame_background_->set_theme_image(GetFrameImage());
620 frame_background_->set_theme_overlay_image(GetFrameOverlayImage());
621 frame_background_->set_top_area_height(GetTopAreaHeight());
622 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
623 // The window manager typically shows a gradient in the native title bar (when
624 // the system title bar pref is set, or when maximized on Ubuntu). Hide the
625 // gradient in the tab strip (by shifting it up vertically) to avoid a
626 // double-gradient effect.
627 if (tp->UsingSystemTheme())
628 frame_background_->set_maximized_top_inset(kGTKThemeCondensedFrameTopInset);
629 #endif
631 frame_background_->PaintMaximized(canvas, this);
633 // TODO(jamescook): Migrate this into FrameBackground.
634 if (!browser_view()->IsToolbarVisible()) {
635 // There's no toolbar to edge the frame border, so we need to draw a bottom
636 // edge. The graphic we use for this has a built in client edge, so we clip
637 // it off the bottom.
638 gfx::ImageSkia* top_center = tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER);
639 int edge_height = top_center->height() - kClientEdgeThickness;
640 canvas->TileImageInt(*top_center, 0,
641 frame()->client_view()->y() - edge_height, width(), edge_height);
645 void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
646 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
647 if (toolbar_bounds.IsEmpty())
648 return;
649 gfx::Point toolbar_origin(toolbar_bounds.origin());
650 ConvertPointToTarget(browser_view(), this, &toolbar_origin);
651 toolbar_bounds.set_origin(toolbar_origin);
653 int x = toolbar_bounds.x();
654 int w = toolbar_bounds.width();
655 int y = toolbar_bounds.y();
656 int h = toolbar_bounds.height();
658 // Gross hack: We split the toolbar images into two pieces, since sometimes
659 // (popup mode) the toolbar isn't tall enough to show the whole image. The
660 // split happens between the top shadow section and the bottom gradient
661 // section so that we never break the gradient.
662 int split_point = kFrameShadowThickness * 2;
663 int bottom_y = y + split_point;
664 ui::ThemeProvider* tp = GetThemeProvider();
665 gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(
666 IDR_CONTENT_TOP_LEFT_CORNER);
667 int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point;
669 // Split our canvas out so we can mask out the corners of the toolbar
670 // without masking out the frame.
671 canvas->SaveLayerAlpha(
672 255, gfx::Rect(x - kClientEdgeThickness, y, w + kClientEdgeThickness * 3,
673 h));
675 // Paint the bottom rect.
676 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
677 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
679 // Tile the toolbar image starting at the frame edge on the left and where the
680 // horizontal tabstrip is (or would be) on the top.
681 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
682 canvas->TileImageInt(*theme_toolbar,
683 x + GetThemeBackgroundXInset(),
684 bottom_y - GetTopInset(),
685 x, bottom_y, w, theme_toolbar->height());
687 // Draw rounded corners for the tab.
688 gfx::ImageSkia* toolbar_left_mask =
689 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
690 gfx::ImageSkia* toolbar_right_mask =
691 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
693 // We mask out the corners by using the DestinationIn transfer mode,
694 // which keeps the RGB pixels from the destination and the alpha from
695 // the source.
696 SkPaint paint;
697 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
699 // Mask the left edge.
700 int left_x = x - kContentEdgeShadowThickness;
701 canvas->DrawImageInt(*toolbar_left_mask, 0, 0, toolbar_left_mask->width(),
702 split_point, left_x, y, toolbar_left_mask->width(),
703 split_point, false, paint);
704 canvas->DrawImageInt(*toolbar_left_mask, 0,
705 toolbar_left_mask->height() - bottom_edge_height,
706 toolbar_left_mask->width(), bottom_edge_height, left_x, bottom_y,
707 toolbar_left_mask->width(), bottom_edge_height, false, paint);
709 // Mask the right edge.
710 int right_x =
711 x + w - toolbar_right_mask->width() + kContentEdgeShadowThickness;
712 canvas->DrawImageInt(*toolbar_right_mask, 0, 0, toolbar_right_mask->width(),
713 split_point, right_x, y, toolbar_right_mask->width(),
714 split_point, false, paint);
715 canvas->DrawImageInt(*toolbar_right_mask, 0,
716 toolbar_right_mask->height() - bottom_edge_height,
717 toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y,
718 toolbar_right_mask->width(), bottom_edge_height, false, paint);
719 canvas->Restore();
721 canvas->DrawImageInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point,
722 left_x, y, toolbar_left->width(), split_point, false);
723 canvas->DrawImageInt(*toolbar_left, 0,
724 toolbar_left->height() - bottom_edge_height, toolbar_left->width(),
725 bottom_edge_height, left_x, bottom_y, toolbar_left->width(),
726 bottom_edge_height, false);
728 gfx::ImageSkia* toolbar_center =
729 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
730 canvas->TileImageInt(*toolbar_center, 0, 0, left_x + toolbar_left->width(),
731 y, right_x - (left_x + toolbar_left->width()),
732 split_point);
734 gfx::ImageSkia* toolbar_right = tp->GetImageSkiaNamed(
735 IDR_CONTENT_TOP_RIGHT_CORNER);
736 canvas->DrawImageInt(*toolbar_right, 0, 0, toolbar_right->width(),
737 split_point, right_x, y, toolbar_right->width(), split_point, false);
738 canvas->DrawImageInt(*toolbar_right, 0,
739 toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
740 bottom_edge_height, right_x, bottom_y, toolbar_right->width(),
741 bottom_edge_height, false);
743 // Draw the content/toolbar separator.
744 canvas->FillRect(
745 gfx::Rect(x + kClientEdgeThickness,
746 toolbar_bounds.bottom() - kClientEdgeThickness,
747 w - (2 * kClientEdgeThickness),
748 kClientEdgeThickness),
749 ThemeProperties::GetDefaultColor(
750 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
753 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
754 ui::ThemeProvider* tp = GetThemeProvider();
755 int client_area_top = frame()->client_view()->y();
756 int image_top = client_area_top;
758 gfx::Rect client_area_bounds =
759 layout_->CalculateClientAreaBounds(width(), height());
760 SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
762 if (browser_view()->IsToolbarVisible()) {
763 // The client edge images always start below the toolbar corner images. The
764 // client edge filled rects start there or at the bottom of the toolbar,
765 // whichever is shorter.
766 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
768 gfx::ImageSkia* content_top_left_corner =
769 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
770 // TODO(oshima): Sanity checks for crbug.com/374273. Remove when it's fixed.
771 CHECK(content_top_left_corner);
772 CHECK(!content_top_left_corner->isNull());
774 image_top += toolbar_bounds.y() + content_top_left_corner->height();
775 client_area_top = std::min(image_top,
776 client_area_top + toolbar_bounds.bottom() - kClientEdgeThickness);
777 } else if (!browser_view()->IsTabStripVisible()) {
778 // The toolbar isn't going to draw a client edge for us, so draw one
779 // ourselves.
780 gfx::ImageSkia* top_left = tp->GetImageSkiaNamed(IDR_APP_TOP_LEFT);
781 gfx::ImageSkia* top_center = tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER);
782 gfx::ImageSkia* top_right = tp->GetImageSkiaNamed(IDR_APP_TOP_RIGHT);
783 int top_edge_y = client_area_top - top_center->height();
784 int height = client_area_top - top_edge_y;
786 canvas->DrawImageInt(*top_left, 0, 0, top_left->width(), height,
787 client_area_bounds.x() - top_left->width(), top_edge_y,
788 top_left->width(), height, false);
789 canvas->TileImageInt(*top_center, 0, 0, client_area_bounds.x(), top_edge_y,
790 client_area_bounds.width(), std::min(height, top_center->height()));
791 canvas->DrawImageInt(*top_right, 0, 0, top_right->width(), height,
792 client_area_bounds.right(), top_edge_y,
793 top_right->width(), height, false);
795 // Draw the toolbar color across the top edge.
796 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
797 client_area_top - kClientEdgeThickness,
798 client_area_bounds.width() + (2 * kClientEdgeThickness),
799 kClientEdgeThickness), toolbar_color);
802 int client_area_bottom =
803 std::max(client_area_top, height() - NonClientBorderThickness());
804 int image_height = client_area_bottom - image_top;
806 // Draw the client edge images.
807 gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
808 canvas->TileImageInt(*right, client_area_bounds.right(), image_top,
809 right->width(), image_height);
810 canvas->DrawImageInt(
811 *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
812 client_area_bounds.right(), client_area_bottom);
813 gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
814 canvas->TileImageInt(*bottom, client_area_bounds.x(),
815 client_area_bottom, client_area_bounds.width(),
816 bottom->height());
817 gfx::ImageSkia* bottom_left =
818 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
819 canvas->DrawImageInt(*bottom_left,
820 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
821 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
822 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
823 image_top, left->width(), image_height);
825 // Draw the toolbar color so that the client edges show the right color even
826 // where not covered by the toolbar image. NOTE: We do this after drawing the
827 // images because the images are meant to alpha-blend atop the frame whereas
828 // these rects are meant to be fully opaque, without anything overlaid.
829 canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
830 client_area_top, kClientEdgeThickness,
831 client_area_bottom + kClientEdgeThickness - client_area_top),
832 toolbar_color);
833 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom,
834 client_area_bounds.width(), kClientEdgeThickness),
835 toolbar_color);
836 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top,
837 kClientEdgeThickness,
838 client_area_bottom + kClientEdgeThickness - client_area_top),
839 toolbar_color);