Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc

Issue 1636703002: Implement MD specs for non-tabbed windows in Ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_layout_constants.h" 9 #include "ash/ash_layout_constants.h"
10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/layout_constants.h" 23 #include "chrome/browser/ui/layout_constants.h"
24 #include "chrome/browser/ui/views/frame/browser_frame.h" 24 #include "chrome/browser/ui/views/frame/browser_frame.h"
25 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" 25 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
26 #include "chrome/browser/ui/views/frame/browser_view.h" 26 #include "chrome/browser/ui/views/frame/browser_view.h"
27 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 27 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
28 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" 28 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h"
29 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 29 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
30 #include "chrome/browser/ui/views/tab_icon_view.h" 30 #include "chrome/browser/ui/views/tab_icon_view.h"
31 #include "chrome/browser/ui/views/tabs/tab_strip.h" 31 #include "chrome/browser/ui/views/tabs/tab_strip.h"
32 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
32 #include "chrome/browser/web_applications/web_app.h" 33 #include "chrome/browser/web_applications/web_app.h"
33 #include "components/signin/core/common/profile_management_switches.h" 34 #include "components/signin/core/common/profile_management_switches.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "extensions/browser/extension_registry.h" 36 #include "extensions/browser/extension_registry.h"
36 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
37 #include "ui/accessibility/ax_view_state.h" 38 #include "ui/accessibility/ax_view_state.h"
38 #include "ui/aura/client/aura_constants.h" 39 #include "ui/aura/client/aura_constants.h"
39 #include "ui/aura/window.h" 40 #include "ui/aura/window.h"
40 #include "ui/base/hit_test.h" 41 #include "ui/base/hit_test.h"
41 #include "ui/base/layout.h" 42 #include "ui/base/layout.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) ? 183 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) ?
183 kTabstripTopSpacingShort : kTabstripTopSpacingTall; 184 kTabstripTopSpacingShort : kTabstripTopSpacingTall;
184 } 185 }
185 186
186 if (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle()) 187 if (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle())
187 return header_painter_->GetHeaderHeight(); 188 return header_painter_->GetHeaderHeight();
188 189
189 int caption_buttons_bottom = caption_button_container_->bounds().bottom(); 190 int caption_buttons_bottom = caption_button_container_->bounds().bottom();
190 191
191 // The toolbar partially overlaps the caption buttons. 192 // The toolbar partially overlaps the caption buttons.
192 if (browser_view()->IsToolbarVisible()) 193 if (IsToolbarVisible())
193 return caption_buttons_bottom - kContentShadowHeight; 194 return caption_buttons_bottom;
194 195
195 return caption_buttons_bottom + kClientEdgeThickness; 196 return caption_buttons_bottom + kClientEdgeThickness;
196 } 197 }
197 198
198 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const { 199 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const {
199 return ash::HeaderPainterUtil::GetThemeBackgroundXInset(); 200 return ash::HeaderPainterUtil::GetThemeBackgroundXInset();
200 } 201 }
201 202
202 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) { 203 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) {
203 if (window_icon_) 204 if (window_icon_)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return; 300 return;
300 } 301 }
301 302
302 caption_button_container_->SetPaintAsActive(ShouldPaintAsActive()); 303 caption_button_container_->SetPaintAsActive(ShouldPaintAsActive());
303 if (web_app_left_header_view_) 304 if (web_app_left_header_view_)
304 web_app_left_header_view_->SetPaintAsActive(ShouldPaintAsActive()); 305 web_app_left_header_view_->SetPaintAsActive(ShouldPaintAsActive());
305 306
306 ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ? 307 ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ?
307 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; 308 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE;
308 header_painter_->PaintHeader(canvas, header_mode); 309 header_painter_->PaintHeader(canvas, header_mode);
309 if (browser_view()->IsToolbarVisible()) 310
311 if (IsToolbarVisible())
310 PaintToolbarBackground(canvas); 312 PaintToolbarBackground(canvas);
311 else if (!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()) 313 PaintContentEdge(canvas);
312 PaintContentEdge(canvas);
313 } 314 }
314 315
315 void BrowserNonClientFrameViewAsh::Layout() { 316 void BrowserNonClientFrameViewAsh::Layout() {
316 // The header must be laid out before computing |painted_height| because the 317 // The header must be laid out before computing |painted_height| because the
317 // computation of |painted_height| for app and popup windows depends on the 318 // computation of |painted_height| for app and popup windows depends on the
318 // position of the window controls. 319 // position of the window controls.
319 header_painter_->LayoutHeader(); 320 header_painter_->LayoutHeader();
320 321
321 int painted_height = GetTopInset(false); 322 int painted_height = GetTopInset(false);
322 if (browser_view()->IsTabStripVisible()) { 323 if (browser_view()->IsTabStripVisible()) {
323 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); 324 painted_height += browser_view()->tabstrip()->GetPreferredSize().height();
324 } else if (browser_view()->IsToolbarVisible()) { 325 } else if (IsToolbarVisible()) {
325 // Paint the header so that it overlaps with the top few pixels of the 326 // Paint the header so that it overlaps with the top few pixels of the
326 // toolbar because the top few pixels of the toolbar are not opaque. 327 // toolbar because the top few pixels of the toolbar are not opaque.
327 const int kToolbarTopEdgeExclusion = 2; 328 const int kToolbarTopEdgeExclusion = 2;
328 painted_height += kToolbarTopEdgeExclusion; 329 painted_height += kToolbarTopEdgeExclusion;
329 } 330 }
330 header_painter_->SetHeaderHeightForPainting(painted_height); 331 header_painter_->SetHeaderHeightForPainting(painted_height);
331 332
332 if (avatar_button()) { 333 if (avatar_button()) {
333 LayoutAvatar(); 334 LayoutAvatar();
334 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right()); 335 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right());
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 535 }
535 536
536 void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader( 537 void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader(
537 gfx::Canvas* canvas) { 538 gfx::Canvas* canvas) {
538 // The light bar header is not themed because theming it does not look good. 539 // The light bar header is not themed because theming it does not look good.
539 canvas->FillRect( 540 canvas->FillRect(
540 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()), 541 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()),
541 SK_ColorBLACK); 542 SK_ColorBLACK);
542 } 543 }
543 544
545 bool BrowserNonClientFrameViewAsh::IsToolbarVisible() const {
546 return browser_view()->IsToolbarVisible() &&
547 !browser_view()->toolbar()->GetPreferredSize().IsEmpty();
548 }
549
544 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { 550 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
545 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); 551 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
546 if (toolbar_bounds.IsEmpty()) 552 if (toolbar_bounds.IsEmpty())
547 return; 553 return;
548 gfx::Point toolbar_origin(toolbar_bounds.origin()); 554 gfx::Point toolbar_origin(toolbar_bounds.origin());
549 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); 555 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
550 toolbar_bounds.set_origin(toolbar_origin); 556 toolbar_bounds.set_origin(toolbar_origin);
557 const int h = toolbar_bounds.height();
558 const bool md = ui::MaterialDesignController::IsModeMaterial();
559 const ui::ThemeProvider* tp = GetThemeProvider();
560 const SkColor separator_color =
561 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR);
551 562
552 int x = toolbar_bounds.x(); 563 if (browser_view()->IsTabStripVisible()) {
553 int w = toolbar_bounds.width(); 564 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
554 int y = toolbar_bounds.y(); 565 int x = toolbar_bounds.x();
555 int h = toolbar_bounds.height(); 566 const int y = toolbar_bounds.y();
556 const ui::ThemeProvider* tp = GetThemeProvider(); 567 const int bg_y =
568 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground();
569 const int w = toolbar_bounds.width();
557 570
558 if (ui::MaterialDesignController::IsModeMaterial()) { 571 if (md) {
559 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { 572 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
560 // Paint the main toolbar image. Since this image is also used to draw 573 // Paint the main toolbar image. Since this image is also used to draw
561 // the tab background, we must use the tab strip offset to compute the 574 // the tab background, we must use the tab strip offset to compute the
562 // image source y position. If you have to debug this code use an image 575 // image source y position. If you have to debug this code use an image
563 // editor to paint a diagonal line through the toolbar image and ensure it 576 // editor to paint a diagonal line through the toolbar image and ensure
564 // lines up across the tab and toolbar. 577 // it lines up across the tab and toolbar.
565 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); 578 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x,
566 canvas->TileImageInt(*theme_toolbar, x + GetThemeBackgroundXInset(), 579 y, w, h);
567 y - GetTopInset(false), x, y, w, 580 } else {
568 theme_toolbar->height()); 581 canvas->FillRect(toolbar_bounds,
569 } else { 582 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
570 canvas->FillRect(toolbar_bounds, 583 }
571 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
572 }
573 584
574 // Draw the separator line atop the toolbar, on the left and right of the 585 // Separator line above the toolbar, which coincides with the bottom edge
575 // tabstrip. 586 // of the tab strip.
576 // TODO(tdanderson): Draw the separator line for non-tabbed windows.
577 if (browser_view()->IsTabStripVisible()) {
578 gfx::Rect separator_rect(x, y, w, 0); 587 gfx::Rect separator_rect(x, y, w, 0);
579 gfx::ScopedCanvas scoped_canvas(canvas); 588 gfx::ScopedCanvas scoped_canvas(canvas);
580 gfx::Rect tabstrip_bounds( 589 gfx::Rect tabstrip_bounds(
581 GetBoundsForTabStrip(browser_view()->tabstrip())); 590 GetBoundsForTabStrip(browser_view()->tabstrip()));
582 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); 591 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds));
583 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds), 592 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds),
584 SkRegion::kDifference_Op); 593 SkRegion::kDifference_Op);
585 separator_rect.set_y(tabstrip_bounds.bottom()); 594 separator_rect.set_y(tabstrip_bounds.bottom());
586 BrowserView::Paint1pxHorizontalLine( 595 BrowserView::Paint1pxHorizontalLine(
587 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), 596 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR),
588 separator_rect, true); 597 separator_rect, true);
598 } else {
599 // Gross hack: We split the toolbar images into two pieces, since
600 // sometimes (popup mode) the toolbar isn't tall enough to show the whole
601 // image. The split happens between the top shadow section and the bottom
602 // gradient section so that we never break the gradient.
603 // NOTE(pkotwicz): If the computation for |bottom_y| is changed, Layout()
604 // must be changed as well.
605 int split_point = kFrameShadowThickness * 2;
606 int bottom_y = y + split_point;
607 int bottom_edge_height = h - split_point;
608
609 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
610 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
611
612 // Paint the main toolbar image. Since this image is also used to draw
613 // the tab background, we must use the tab strip offset to compute the
614 // image source y position. If you have to debug this code use an image
615 // editor to paint a diagonal line through the toolbar image and ensure it
616 // lines up across the tab and toolbar.
617 canvas->TileImageInt(
618 *bg,
619 x + GetThemeBackgroundXInset(),
620 bottom_y - bg_y,
621 x, bottom_y,
622 w, bg->height());
623
624 // The pre-material design content area line has a shadow that extends a
625 // couple of pixels above the toolbar bounds.
626 const int kContentShadowHeight = 2;
627 gfx::ImageSkia* toolbar_top =
628 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
629 canvas->TileImageInt(*toolbar_top,
630 0, 0,
631 x, y - kContentShadowHeight,
632 w, split_point + kContentShadowHeight + 1);
633
634 // Draw the "lightening" shade line around the edges of the toolbar.
635 gfx::ImageSkia* toolbar_left =
636 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
637 canvas->TileImageInt(*toolbar_left,
638 0, 0,
639 x + kClientEdgeThickness,
640 y + kClientEdgeThickness + kContentShadowHeight,
641 toolbar_left->width(), bg->height());
642 gfx::ImageSkia* toolbar_right =
643 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
644 canvas->TileImageInt(*toolbar_right,
645 0, 0,
646 w - toolbar_right->width() - 2*kClientEdgeThickness,
647 y + kClientEdgeThickness + kContentShadowHeight,
648 toolbar_right->width(), bg->height());
589 } 649 }
650 }
590 651
591 // Draw the content/toolbar separator. 652 // Draw the toolbar/content separator.
592 toolbar_bounds.Inset(kClientEdgeThickness, 0); 653 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness,
593 BrowserView::Paint1pxHorizontalLine( 654 kClientEdgeThickness, 0);
594 canvas, 655 if (md) {
595 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), 656 canvas->FillRect(toolbar_bounds, SK_ColorWHITE);
tdanderson 2016/01/29 22:28:43 Without line 656, at 2x device scale factor we wil
Peter Kasting 2016/01/30 02:53:37 This is actually a bug on non-Ash as well; I must
tdanderson 2016/02/01 22:17:51 Thanks, I've added a TODO in the next patch set.
596 toolbar_bounds, true); 657 BrowserView::Paint1pxHorizontalLine(canvas, separator_color,
658 toolbar_bounds, true);
597 } else { 659 } else {
598 // Gross hack: We split the toolbar images into two pieces, since sometimes 660 canvas->FillRect(toolbar_bounds, separator_color);
599 // (popup mode) the toolbar isn't tall enough to show the whole image. The
600 // split happens between the top shadow section and the bottom gradient
601 // section so that we never break the gradient.
602 // NOTE(pkotwicz): If the computation for |bottom_y| is changed, Layout()
603 // must be changed as well.
604 int split_point = kFrameShadowThickness * 2;
605 int bottom_y = y + split_point;
606 int bottom_edge_height = h - split_point;
607
608 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
609 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
610
611 // Paint the main toolbar image. Since this image is also used to draw the
612 // tab background, we must use the tab strip offset to compute the image
613 // source y position. If you have to debug this code use an image editor
614 // to paint a diagonal line through the toolbar image and ensure it lines up
615 // across the tab and toolbar.
616 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
617 canvas->TileImageInt(
618 *theme_toolbar,
619 x + GetThemeBackgroundXInset(),
620 bottom_y - GetTopInset(false),
621 x, bottom_y,
622 w, theme_toolbar->height());
623
624 // The pre-material design content area line has a shadow that extends a
625 // couple of pixels above the toolbar bounds.
626 const int kContentShadowHeight = 2;
627 gfx::ImageSkia* toolbar_top = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
628 canvas->TileImageInt(*toolbar_top,
629 0, 0,
630 x, y - kContentShadowHeight,
631 w, split_point + kContentShadowHeight + 1);
632
633 // Draw the "lightening" shade line around the edges of the toolbar.
634 gfx::ImageSkia* toolbar_left =
635 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
636 canvas->TileImageInt(*toolbar_left,
637 0, 0,
638 x + kClientEdgeThickness,
639 y + kClientEdgeThickness + kContentShadowHeight,
640 toolbar_left->width(), theme_toolbar->height());
641 gfx::ImageSkia* toolbar_right =
642 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
643 canvas->TileImageInt(*toolbar_right,
644 0, 0,
645 w - toolbar_right->width() - 2 * kClientEdgeThickness,
646 y + kClientEdgeThickness + kContentShadowHeight,
647 toolbar_right->width(), theme_toolbar->height());
648
649 // Draw the content/toolbar separator.
650 canvas->FillRect(
651 gfx::Rect(x + kClientEdgeThickness,
652 toolbar_bounds.bottom() - kClientEdgeThickness,
653 w - (2 * kClientEdgeThickness), kClientEdgeThickness),
654 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR));
655 } 661 }
656 } 662 }
657 663
658 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { 664 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) {
659 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); 665 if (browser_view()->IsTabStripVisible())
660 canvas->FillRect( 666 return;
661 gfx::Rect(0, caption_button_container_->bounds().bottom(), width(), 667
662 kClientEdgeThickness), 668 gfx::Rect separator_rect(
663 GetThemeProvider()->GetColor( 669 0, caption_button_container_->bounds().bottom(), width(), 0);
664 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); 670 BrowserView::Paint1pxHorizontalLine(
tdanderson 2016/01/29 22:28:43 DefaultHeaderPainter::PaintTitleBar() already pain
Peter Kasting 2016/01/30 02:53:37 I would try to figure out why this isn't the case
tdanderson 2016/02/01 22:17:51 Fixed this in the next patch set.
671 canvas, GetThemeProvider()->GetColor(
672 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
673 separator_rect, true);
665 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698