Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_non_client_frame_view_ash.cc
blobf341dfc74b6dcab931ca1deb26e89f0163105985
1 // Copyright 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/browser_non_client_frame_view_ash.h"
7 #include <algorithm>
9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
10 #include "ash/frame/default_header_painter.h"
11 #include "ash/frame/frame_border_hit_test_controller.h"
12 #include "ash/frame/header_painter_util.h"
13 #include "ash/shell.h"
14 #include "base/profiler/scoped_tracker.h"
15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/themes/theme_properties.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/browser/ui/views/frame/browser_frame.h"
22 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
23 #include "chrome/browser/ui/views/frame/browser_view.h"
24 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
25 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h"
26 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
27 #include "chrome/browser/ui/views/tab_icon_view.h"
28 #include "chrome/browser/ui/views/tabs/tab_strip.h"
29 #include "chrome/browser/web_applications/web_app.h"
30 #include "components/signin/core/common/profile_management_switches.h"
31 #include "content/public/browser/web_contents.h"
32 #include "extensions/browser/extension_registry.h"
33 #include "grit/theme_resources.h"
34 #include "ui/accessibility/ax_view_state.h"
35 #include "ui/aura/client/aura_constants.h"
36 #include "ui/aura/window.h"
37 #include "ui/base/hit_test.h"
38 #include "ui/base/layout.h"
39 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/base/theme_provider.h"
41 #include "ui/compositor/layer_animator.h"
42 #include "ui/gfx/canvas.h"
43 #include "ui/gfx/geometry/rect_conversions.h"
44 #include "ui/gfx/image/image_skia.h"
45 #include "ui/views/controls/label.h"
46 #include "ui/views/layout/layout_constants.h"
47 #include "ui/views/widget/widget.h"
48 #include "ui/views/widget/widget_delegate.h"
50 #if defined(ENABLE_SUPERVISED_USERS)
51 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h"
52 #endif
54 namespace {
56 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
57 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
58 // user).
59 const int kAvatarBottomSpacing = 2;
60 // There are 2 px on each side of the avatar (between the frame border and
61 // it on the left, and between it and the tabstrip on the right).
62 const int kAvatarSideSpacing = 2;
63 // Space between the new avatar button and the minimize button.
64 const int kNewAvatarButtonOffset = 5;
65 // Space between left edge of window and tabstrip.
66 const int kTabstripLeftSpacing = 0;
67 // Space between right edge of tabstrip and maximize button.
68 const int kTabstripRightSpacing = 10;
69 // Height of the shadow of the content area, at the top of the toolbar.
70 const int kContentShadowHeight = 1;
71 // Space between top of window and top of tabstrip for tall headers, such as
72 // for restored windows, apps, etc.
73 const int kTabstripTopSpacingTall = 7;
74 // Space between top of window and top of tabstrip for short headers, such as
75 // for maximized windows, pop-ups, etc.
76 const int kTabstripTopSpacingShort = 0;
77 // Height of the shadow in the tab image, used to ensure clicks in the shadow
78 // area still drag restored windows. This keeps the clickable area large enough
79 // to hit easily.
80 const int kTabShadowHeight = 4;
82 // Combines View::ConvertPointToTarget() and View::HitTest() for a given
83 // |point|. Converts |point| from |src| to |dst| and hit tests it against |dst|.
84 bool ConvertedHitTest(views::View* src,
85 views::View* dst,
86 const gfx::Point& point) {
87 DCHECK(src);
88 DCHECK(dst);
89 gfx::Point converted_point(point);
90 views::View::ConvertPointToTarget(src, dst, &converted_point);
91 return dst->HitTestPoint(converted_point);
94 } // namespace
96 ///////////////////////////////////////////////////////////////////////////////
97 // BrowserNonClientFrameViewAsh, public:
99 // static
100 const char BrowserNonClientFrameViewAsh::kViewClassName[] =
101 "BrowserNonClientFrameViewAsh";
103 BrowserNonClientFrameViewAsh::BrowserNonClientFrameViewAsh(
104 BrowserFrame* frame,
105 BrowserView* browser_view)
106 : BrowserNonClientFrameView(frame, browser_view),
107 caption_button_container_(nullptr),
108 web_app_left_header_view_(nullptr),
109 window_icon_(nullptr),
110 frame_border_hit_test_controller_(
111 new ash::FrameBorderHitTestController(frame)) {
112 ash::Shell::GetInstance()->AddShellObserver(this);
115 BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() {
116 ash::Shell::GetInstance()->RemoveShellObserver(this);
119 void BrowserNonClientFrameViewAsh::Init() {
120 caption_button_container_ = new ash::FrameCaptionButtonContainerView(frame());
121 caption_button_container_->UpdateSizeButtonVisibility();
122 AddChildView(caption_button_container_);
124 // Initializing the TabIconView is expensive, so only do it if we need to.
125 if (browser_view()->ShouldShowWindowIcon()) {
126 window_icon_ = new TabIconView(this, nullptr);
127 window_icon_->set_is_light(true);
128 AddChildView(window_icon_);
129 window_icon_->Update();
132 UpdateAvatar();
134 // HeaderPainter handles layout.
135 if (UsePackagedAppHeaderStyle()) {
136 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter;
137 header_painter_.reset(header_painter);
138 header_painter->Init(frame(), this, caption_button_container_);
139 if (window_icon_) {
140 header_painter->UpdateLeftHeaderView(window_icon_);
142 } else if (UseWebAppHeaderStyle()) {
143 web_app_left_header_view_ = new WebAppLeftHeaderView(browser_view());
144 AddChildView(web_app_left_header_view_);
146 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter;
147 header_painter_.reset(header_painter);
148 header_painter->Init(frame(), this, caption_button_container_);
149 header_painter->UpdateLeftHeaderView(web_app_left_header_view_);
150 } else {
151 BrowserHeaderPainterAsh* header_painter = new BrowserHeaderPainterAsh;
152 header_painter_.reset(header_painter);
153 header_painter->Init(frame(), browser_view(), this, window_icon_,
154 caption_button_container_);
158 ///////////////////////////////////////////////////////////////////////////////
159 // BrowserNonClientFrameView:
161 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip(
162 views::View* tabstrip) const {
163 if (!tabstrip)
164 return gfx::Rect();
166 // When the tab strip is painted in the immersive fullscreen light bar style,
167 // the caption buttons and the avatar button are not visible. However, their
168 // bounds are still used to compute the tab strip bounds so that the tabs have
169 // the same horizontal position when the tab strip is painted in the immersive
170 // light bar style as when the top-of-window views are revealed.
171 int left_inset = GetTabStripLeftInset();
172 int right_inset = GetTabStripRightInset();
173 return gfx::Rect(left_inset,
174 GetTopInset(),
175 std::max(0, width() - left_inset - right_inset),
176 tabstrip->GetPreferredSize().height());
179 int BrowserNonClientFrameViewAsh::GetTopInset() const {
180 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle())
181 return 0;
183 if (browser_view()->IsTabStripVisible()) {
184 if (frame()->IsMaximized() || frame()->IsFullscreen())
185 return kTabstripTopSpacingShort;
186 else
187 return kTabstripTopSpacingTall;
190 if (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle())
191 return header_painter_->GetHeaderHeightForPainting();
193 int caption_buttons_bottom = caption_button_container_->bounds().bottom();
195 // The toolbar partially overlaps the caption buttons.
196 if (browser_view()->IsToolbarVisible())
197 return caption_buttons_bottom - kContentShadowHeight;
199 return caption_buttons_bottom + kClientEdgeThickness;
202 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const {
203 return ash::HeaderPainterUtil::GetThemeBackgroundXInset();
206 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) {
207 if (window_icon_)
208 window_icon_->Update();
211 void BrowserNonClientFrameViewAsh::UpdateToolbar() {
212 if (web_app_left_header_view_)
213 web_app_left_header_view_->Update();
216 views::View* BrowserNonClientFrameViewAsh::GetLocationIconView() const {
217 if (web_app_left_header_view_)
218 return web_app_left_header_view_->GetLocationIconView();
220 return nullptr;
223 ///////////////////////////////////////////////////////////////////////////////
224 // views::NonClientFrameView:
226 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const {
227 // The ClientView must be flush with the top edge of the widget so that the
228 // web contents can take up the entire screen in immersive fullscreen (with
229 // or without the top-of-window views revealed). When in immersive fullscreen
230 // and the top-of-window views are revealed, the TopContainerView paints the
231 // window header by redirecting paints from its background to
232 // BrowserNonClientFrameViewAsh.
233 return bounds();
236 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds(
237 const gfx::Rect& client_bounds) const {
238 return client_bounds;
241 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
242 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this,
243 caption_button_container_, point);
245 // See if the point is actually within either of the avatar menu buttons.
246 if (hit_test == HTCAPTION && avatar_button() &&
247 ConvertedHitTest(this, avatar_button(), point)) {
248 #if defined(OS_CHROMEOS)
249 // In ChromeOS, a browser window which has an avatar badging on the top
250 // left corner means it's a teleported browser window. We should treat the
251 // avatar as part of the browser non client frame (e.g., clicking on it
252 // allows the user to drag the browser window around.)
253 return HTCAPTION;
254 #else
255 return HTCLIENT;
256 #endif
259 if (hit_test == HTCAPTION && new_avatar_button() &&
260 ConvertedHitTest(this, new_avatar_button(), point)) {
261 return HTCLIENT;
264 // See if the point is actually within the web app back button.
265 if (hit_test == HTCAPTION && web_app_left_header_view_ &&
266 ConvertedHitTest(this, web_app_left_header_view_, point)) {
267 return HTCLIENT;
270 #if defined(ENABLE_SUPERVISED_USERS)
271 // ...or within the avatar label, if it's a supervised user.
272 if (hit_test == HTCAPTION && supervised_user_avatar_label() &&
273 ConvertedHitTest(this, supervised_user_avatar_label(), point)) {
274 return HTCLIENT;
276 #endif
278 // When the window is restored we want a large click target above the tabs
279 // to drag the window, so redirect clicks in the tab's shadow to caption.
280 if (hit_test == HTCLIENT &&
281 !(frame()->IsMaximized() || frame()->IsFullscreen())) {
282 // Convert point to client coordinates.
283 gfx::Point client_point(point);
284 View::ConvertPointToTarget(this, frame()->client_view(), &client_point);
285 // Report hits in shadow at top of tabstrip as caption.
286 gfx::Rect tabstrip_bounds(browser_view()->tabstrip()->bounds());
287 if (client_point.y() < tabstrip_bounds.y() + kTabShadowHeight)
288 hit_test = HTCAPTION;
290 return hit_test;
293 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size,
294 gfx::Path* window_mask) {
295 // Aura does not use window masks.
298 void BrowserNonClientFrameViewAsh::ResetWindowControls() {
299 // Hide the caption buttons in immersive fullscreen when the tab light bar
300 // is visible because it's confusing when the user hovers or clicks in the
301 // top-right of the screen and hits one.
302 bool button_visibility = !UseImmersiveLightbarHeaderStyle();
303 caption_button_container_->SetVisible(button_visibility);
305 caption_button_container_->ResetWindowControls();
308 void BrowserNonClientFrameViewAsh::UpdateWindowIcon() {
309 if (window_icon_)
310 window_icon_->SchedulePaint();
313 void BrowserNonClientFrameViewAsh::UpdateWindowTitle() {
314 if (!frame()->IsFullscreen())
315 header_painter_->SchedulePaintForTitle();
318 void BrowserNonClientFrameViewAsh::SizeConstraintsChanged() {
321 ///////////////////////////////////////////////////////////////////////////////
322 // views::View:
324 void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) {
325 if (!ShouldPaint())
326 return;
328 if (UseImmersiveLightbarHeaderStyle()) {
329 PaintImmersiveLightbarStyleHeader(canvas);
330 return;
333 caption_button_container_->SetPaintAsActive(ShouldPaintAsActive());
334 if (web_app_left_header_view_)
335 web_app_left_header_view_->SetPaintAsActive(ShouldPaintAsActive());
337 ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ?
338 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE;
339 header_painter_->PaintHeader(canvas, header_mode);
340 if (browser_view()->IsToolbarVisible())
341 PaintToolbarBackground(canvas);
342 else if (!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle())
343 PaintContentEdge(canvas);
346 void BrowserNonClientFrameViewAsh::Layout() {
347 // The header must be laid out before computing |painted_height| because the
348 // computation of |painted_height| for app and popup windows depends on the
349 // position of the window controls.
350 header_painter_->LayoutHeader();
352 int painted_height = 0;
353 if (browser_view()->IsTabStripVisible()) {
354 painted_height = GetTopInset() +
355 browser_view()->tabstrip()->GetPreferredSize().height();
356 } else if (browser_view()->IsToolbarVisible()) {
357 // Paint the header so that it overlaps with the top few pixels of the
358 // toolbar because the top few pixels of the toolbar are not opaque.
359 painted_height = GetTopInset() + kFrameShadowThickness * 2;
360 } else {
361 painted_height = GetTopInset();
363 header_painter_->SetHeaderHeightForPainting(painted_height);
365 if (avatar_button()) {
366 LayoutAvatar();
367 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right());
368 } else {
369 if (new_avatar_button())
370 LayoutNewStyleAvatar();
371 header_painter_->UpdateLeftViewXInset(
372 ash::HeaderPainterUtil::GetDefaultLeftViewXInset());
374 BrowserNonClientFrameView::Layout();
377 const char* BrowserNonClientFrameViewAsh::GetClassName() const {
378 return kViewClassName;
381 void BrowserNonClientFrameViewAsh::GetAccessibleState(
382 ui::AXViewState* state) {
383 state->role = ui::AX_ROLE_TITLE_BAR;
386 gfx::Size BrowserNonClientFrameViewAsh::GetMinimumSize() const {
387 gfx::Size min_client_view_size(frame()->client_view()->GetMinimumSize());
388 int min_width = std::max(header_painter_->GetMinimumHeaderWidth(),
389 min_client_view_size.width());
390 if (browser_view()->IsTabStripVisible()) {
391 // Ensure that the minimum width is enough to hold a minimum width tab strip
392 // at its usual insets.
393 int min_tabstrip_width =
394 browser_view()->tabstrip()->GetMinimumSize().width();
395 min_width = std::max(min_width,
396 min_tabstrip_width + GetTabStripLeftInset() + GetTabStripRightInset());
398 return gfx::Size(min_width, min_client_view_size.height());
401 void BrowserNonClientFrameViewAsh::
402 ChildPreferredSizeChanged(views::View* child) {
403 // FrameCaptionButtonContainerView animates the visibility changes in
404 // UpdateSizeButtonVisibility(false). Due to this a new size is not available
405 // until the completion of the animation. Layout in response to the preferred
406 // size changes.
407 if (!browser_view()->initialized())
408 return;
409 if (child == caption_button_container_ || child == new_avatar_button()) {
410 InvalidateLayout();
411 frame()->GetRootView()->Layout();
415 ///////////////////////////////////////////////////////////////////////////////
416 // ash::ShellObserver:
418 void BrowserNonClientFrameViewAsh::OnMaximizeModeStarted() {
419 caption_button_container_->UpdateSizeButtonVisibility();
420 InvalidateLayout();
421 frame()->client_view()->InvalidateLayout();
422 frame()->GetRootView()->Layout();
425 void BrowserNonClientFrameViewAsh::OnMaximizeModeEnded() {
426 caption_button_container_->UpdateSizeButtonVisibility();
427 InvalidateLayout();
428 frame()->client_view()->InvalidateLayout();
429 frame()->GetRootView()->Layout();
432 ///////////////////////////////////////////////////////////////////////////////
433 // chrome::TabIconViewModel:
435 bool BrowserNonClientFrameViewAsh::ShouldTabIconViewAnimate() const {
436 // This function is queried during the creation of the window as the
437 // TabIconView we host is initialized, so we need to null check the selected
438 // WebContents because in this condition there is not yet a selected tab.
439 content::WebContents* current_tab = browser_view()->GetActiveWebContents();
440 return current_tab ? current_tab->IsLoading() : false;
443 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() {
444 views::WidgetDelegate* delegate = frame()->widget_delegate();
445 if (!delegate)
446 return gfx::ImageSkia();
447 return delegate->GetWindowIcon();
450 ///////////////////////////////////////////////////////////////////////////////
451 // views::ButtonListener:
453 void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender,
454 const ui::Event& event) {
455 DCHECK(sender == new_avatar_button());
456 int command = IDC_SHOW_AVATAR_MENU;
457 if (event.IsMouseEvent() &&
458 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) {
459 command = IDC_SHOW_FAST_USER_SWITCHER;
461 chrome::ExecuteCommand(browser_view()->browser(), command);
464 ///////////////////////////////////////////////////////////////////////////////
465 // BrowserNonClientFrameViewAsh, protected:
467 // BrowserNonClientFrameView:
468 void BrowserNonClientFrameViewAsh::UpdateNewAvatarButtonImpl() {
469 UpdateNewAvatarButton(this, NewAvatarButton::NATIVE_BUTTON);
472 ///////////////////////////////////////////////////////////////////////////////
473 // BrowserNonClientFrameViewAsh, private:
475 // views::NonClientFrameView:
476 bool BrowserNonClientFrameViewAsh::DoesIntersectRect(
477 const views::View* target,
478 const gfx::Rect& rect) const {
479 CHECK_EQ(target, this);
480 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) {
481 // |rect| is outside BrowserNonClientFrameViewAsh's bounds.
482 return false;
485 TabStrip* tabstrip = browser_view()->tabstrip();
486 if (tabstrip && browser_view()->IsTabStripVisible()) {
487 // Claim |rect| only if it is above the bottom of the tabstrip in a non-tab
488 // portion.
489 gfx::RectF rect_in_tabstrip_coords_f(rect);
490 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
491 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
492 rect_in_tabstrip_coords_f);
494 if (rect_in_tabstrip_coords.y() > tabstrip->height())
495 return false;
497 return !tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
498 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
501 // Claim |rect| if it is above the top of the topmost view in the client area.
502 return rect.y() < GetTopInset();
505 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
506 return avatar_button() ? kAvatarSideSpacing +
507 browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing :
508 kTabstripLeftSpacing;
511 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const {
512 int tabstrip_width = kTabstripRightSpacing +
513 caption_button_container_->GetPreferredSize().width();
515 return new_avatar_button() ? kNewAvatarButtonOffset +
516 new_avatar_button()->GetPreferredSize().width() + tabstrip_width :
517 tabstrip_width;
520 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
521 ImmersiveModeController* immersive_controller =
522 browser_view()->immersive_mode_controller();
523 return immersive_controller->IsEnabled() &&
524 !immersive_controller->IsRevealed() &&
525 browser_view()->IsTabStripVisible();
528 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const {
529 // Use the packaged app style for apps that aren't using the newer WebApp
530 // style, and that aren't bookmark apps.
531 if (!browser_view()->browser()->is_app() || UseWebAppHeaderStyle())
532 return false;
534 const std::string extension_id = web_app::GetExtensionIdFromApplicationName(
535 browser_view()->browser()->app_name());
536 const extensions::Extension* extension =
537 extensions::ExtensionRegistry::Get(browser_view()->browser()->profile())
538 ->GetExtensionById(extension_id,
539 extensions::ExtensionRegistry::EVERYTHING);
540 return !extension || !extension->from_bookmark();
543 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const {
544 return browser_view()->browser()->SupportsWindowFeature(
545 Browser::FEATURE_WEBAPPFRAME);
548 void BrowserNonClientFrameViewAsh::LayoutAvatar() {
549 DCHECK(avatar_button());
550 #if !defined(OS_CHROMEOS)
551 // ChromeOS shows avatar on V1 app.
552 DCHECK(browser_view()->IsTabStripVisible());
553 #endif
554 gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon();
556 int avatar_bottom = GetTopInset() +
557 browser_view()->GetTabStripHeight() - kAvatarBottomSpacing;
558 int avatar_restored_y = avatar_bottom - incognito_icon.height();
559 int avatar_y =
560 (browser_view()->IsTabStripVisible() &&
561 (frame()->IsMaximized() || frame()->IsFullscreen())) ?
562 GetTopInset() + kContentShadowHeight : avatar_restored_y;
564 // Hide the incognito icon in immersive fullscreen when the tab light bar is
565 // visible because the header is too short for the icognito icon to be
566 // recognizable.
567 bool avatar_visible = !UseImmersiveLightbarHeaderStyle();
568 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0;
570 gfx::Rect avatar_bounds(kAvatarSideSpacing,
571 avatar_y,
572 incognito_icon.width(),
573 avatar_height);
574 avatar_button()->SetBoundsRect(avatar_bounds);
575 avatar_button()->SetVisible(avatar_visible);
578 void BrowserNonClientFrameViewAsh::LayoutNewStyleAvatar() {
579 DCHECK(switches::IsNewAvatarMenu());
580 if (!new_avatar_button())
581 return;
583 gfx::Size button_size = new_avatar_button()->GetPreferredSize();
584 int button_x = width() -
585 caption_button_container_->GetPreferredSize().width() -
586 kNewAvatarButtonOffset - button_size.width();
588 new_avatar_button()->SetBounds(
589 button_x,
591 button_size.width(),
592 caption_button_container_->GetPreferredSize().height());
595 bool BrowserNonClientFrameViewAsh::ShouldPaint() const {
596 if (!frame()->IsFullscreen())
597 return true;
599 // We need to paint when in immersive fullscreen and either:
600 // - The top-of-window views are revealed.
601 // - The lightbar style tabstrip is visible.
602 ImmersiveModeController* immersive_mode_controller =
603 browser_view()->immersive_mode_controller();
604 return immersive_mode_controller->IsEnabled() &&
605 (immersive_mode_controller->IsRevealed() ||
606 UseImmersiveLightbarHeaderStyle());
609 void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader(
610 gfx::Canvas* canvas) {
611 // The light bar header is not themed because theming it does not look good.
612 canvas->FillRect(
613 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()),
614 SK_ColorBLACK);
617 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
618 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
619 if (toolbar_bounds.IsEmpty())
620 return;
621 gfx::Point toolbar_origin(toolbar_bounds.origin());
622 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
623 toolbar_bounds.set_origin(toolbar_origin);
625 int x = toolbar_bounds.x();
626 int w = toolbar_bounds.width();
627 int y = toolbar_bounds.y();
628 int h = toolbar_bounds.height();
630 // Gross hack: We split the toolbar images into two pieces, since sometimes
631 // (popup mode) the toolbar isn't tall enough to show the whole image. The
632 // split happens between the top shadow section and the bottom gradient
633 // section so that we never break the gradient.
634 // NOTE(pkotwicz): If the computation for |bottom_y| is changed, Layout() must
635 // be changed as well.
636 int split_point = kFrameShadowThickness * 2;
637 int bottom_y = y + split_point;
638 ui::ThemeProvider* tp = GetThemeProvider();
639 int bottom_edge_height = h - split_point;
641 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
642 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
644 // Paint the main toolbar image. Since this image is also used to draw the
645 // tab background, we must use the tab strip offset to compute the image
646 // source y position. If you have to debug this code use an image editor
647 // to paint a diagonal line through the toolbar image and ensure it lines up
648 // across the tab and toolbar.
649 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
650 canvas->TileImageInt(
651 *theme_toolbar,
652 x + GetThemeBackgroundXInset(),
653 bottom_y - GetTopInset(),
654 x, bottom_y,
655 w, theme_toolbar->height());
657 // The content area line has a shadow that extends a couple of pixels above
658 // the toolbar bounds.
659 const int kContentShadowHeight = 2;
660 gfx::ImageSkia* toolbar_top = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
661 canvas->TileImageInt(*toolbar_top,
662 0, 0,
663 x, y - kContentShadowHeight,
664 w, split_point + kContentShadowHeight + 1);
666 // Draw the "lightening" shade line around the edges of the toolbar.
667 gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
668 canvas->TileImageInt(*toolbar_left,
669 0, 0,
670 x + kClientEdgeThickness,
671 y + kClientEdgeThickness + kContentShadowHeight,
672 toolbar_left->width(), theme_toolbar->height());
673 gfx::ImageSkia* toolbar_right =
674 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
675 canvas->TileImageInt(*toolbar_right,
676 0, 0,
677 w - toolbar_right->width() - 2 * kClientEdgeThickness,
678 y + kClientEdgeThickness + kContentShadowHeight,
679 toolbar_right->width(), theme_toolbar->height());
681 // Draw the content/toolbar separator.
682 canvas->FillRect(
683 gfx::Rect(x + kClientEdgeThickness,
684 toolbar_bounds.bottom() - kClientEdgeThickness,
685 w - (2 * kClientEdgeThickness),
686 kClientEdgeThickness),
687 ThemeProperties::GetDefaultColor(
688 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
691 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) {
692 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle());
693 canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
694 width(), kClientEdgeThickness),
695 ThemeProperties::GetDefaultColor(
696 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));