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

Unified Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc

Issue 189463013: [Refactor] Move code for painting the window header for browser windows out of ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
index a79a29b12633a21e0724ed7cb35c035ab783c6bb..b6fad050b0b4c9de1db8522d527ed40439a30d84 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
@@ -6,14 +6,16 @@
#include "ash/ash_switches.h"
#include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
+#include "ash/wm/default_header_painter.h"
#include "ash/wm/frame_border_hit_test_controller.h"
-#include "ash/wm/header_painter.h"
+#include "ash/wm/header_metrics.h"
#include "base/command_line.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
+#include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/tab_icon_view.h"
@@ -79,7 +81,6 @@ BrowserNonClientFrameViewAsh::BrowserNonClientFrameViewAsh(
: BrowserNonClientFrameView(frame, browser_view),
caption_button_container_(NULL),
window_icon_(NULL),
- header_painter_(new ash::HeaderPainter),
frame_border_hit_test_controller_(
new ash::FrameBorderHitTestController(frame)) {
}
@@ -104,10 +105,17 @@ void BrowserNonClientFrameViewAsh::Init() {
UpdateAvatarInfo();
// HeaderPainter handles layout.
- ash::HeaderPainter::Style header_style = UsePackagedAppHeaderStyle() ?
- ash::HeaderPainter::STYLE_OTHER : ash::HeaderPainter::STYLE_BROWSER;
- header_painter_->Init(header_style, frame(), this, window_icon_,
- caption_button_container_);
+ if (UsePackagedAppHeaderStyle()) {
+ ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter;
+ header_painter->Init(frame(), this, window_icon_,
+ caption_button_container_);
+ header_painter_.reset(header_painter);
James Cook 2014/03/10 17:32:30 Out of curiosity, why reset after Init()? Does he
pkotwicz 2014/03/14 17:56:22 Init is not part of the ash::HeaderPainter interfa
James Cook 2014/03/14 18:27:15 That makes sense. It just looked odd to my reading
pkotwicz 2014/03/16 17:27:18 I swapped the order of lines 110 and 112. Hopefull
+ } else {
+ BrowserHeaderPainterAsh* header_painter = new BrowserHeaderPainterAsh;
+ header_painter->Init(frame(), browser_view(), this, window_icon_,
+ caption_button_container_);
+ header_painter_.reset(header_painter);
+ }
}
///////////////////////////////////////////////////////////////////////////////
@@ -142,19 +150,20 @@ int BrowserNonClientFrameViewAsh::GetTopInset() const {
return kTabstripTopSpacingTall;
}
+ if (UsePackagedAppHeaderStyle())
+ return header_painter_->GetHeaderHeightForPainting();
+
int caption_buttons_bottom = caption_button_container_->bounds().bottom();
// The toolbar partially overlaps the caption buttons.
if (browser_view()->IsToolbarVisible())
return caption_buttons_bottom - kContentShadowHeight;
- int separator_thickness = UsePackagedAppHeaderStyle() ?
- header_painter_->HeaderContentSeparatorSize() : kClientEdgeThickness;
- return caption_buttons_bottom + separator_thickness;
+ return caption_buttons_bottom + kClientEdgeThickness;
}
int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const {
- return header_painter_->GetThemeBackgroundXInset();
+ return ash::HeaderMetrics::GetThemeBackgroundXInset();
}
void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) {
@@ -172,17 +181,17 @@ gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const {
// and the top-of-window views are revealed, the TopContainerView paints the
// window header by redirecting paints from its background to
// BrowserNonClientFrameViewAsh.
- return ash::HeaderPainter::GetBoundsForClientView(0, bounds());
+ return bounds();
}
gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const {
- return ash::HeaderPainter::GetWindowBoundsForClientBounds(0, client_bounds);
+ return client_bounds;
}
int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this,
- header_painter_.get(), point);
+ caption_button_container_, point);
// See if the point is actually within the avatar menu button or within
// the avatar label.
@@ -228,7 +237,7 @@ void BrowserNonClientFrameViewAsh::UpdateWindowIcon() {
void BrowserNonClientFrameViewAsh::UpdateWindowTitle() {
if (!frame()->IsFullscreen())
- header_painter_->SchedulePaintForTitle(BrowserFrame::GetTitleFontList());
+ header_painter_->SchedulePaintForTitle();
}
///////////////////////////////////////////////////////////////////////////////
@@ -245,52 +254,33 @@ void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) {
caption_button_container_->SetPaintAsActive(ShouldPaintAsActive());
- // The primary header image changes based on window activation state and
- // theme, so we look it up for each paint.
- int theme_frame_image_id = 0;
- int theme_frame_overlay_image_id = 0;
- if (browser_view()->IsTabStripVisible()) {
- GetFrameImageIdsForTabbedBrowser(&theme_frame_image_id,
- &theme_frame_overlay_image_id);
- } else if (browser_view()->browser()->is_app()) {
- theme_frame_image_id = GetFrameImageIdForHostedApp();
- } else {
- theme_frame_image_id = GetFrameImageIdForBrowserPopup();
- }
-
ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ?
ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE;
- header_painter_->PaintHeader(
- canvas,
- header_mode,
- theme_frame_image_id,
- theme_frame_overlay_image_id);
- if (browser_view()->ShouldShowWindowTitle())
- header_painter_->PaintTitleBar(canvas, BrowserFrame::GetTitleFontList());
+ header_painter_->PaintHeader(canvas, header_mode);
if (browser_view()->IsToolbarVisible())
PaintToolbarBackground(canvas);
- else
+ else if (!UsePackagedAppHeaderStyle())
PaintContentEdge(canvas);
}
void BrowserNonClientFrameViewAsh::Layout() {
- // The header must be laid out before computing |header_height| because the
- // computation of |header_height| for app and popup windows depends on the
+ // The header must be laid out before computing |painted_height| because the
+ // computation of |painted_height| for app and popup windows depends on the
// position of the window controls.
header_painter_->LayoutHeader();
- int header_height = 0;
+ int painted_height = 0;
if (browser_view()->IsTabStripVisible()) {
- header_height = GetTopInset() +
+ painted_height = GetTopInset() +
browser_view()->tabstrip()->GetPreferredSize().height();
} else if (browser_view()->IsToolbarVisible()) {
- // Set the header's height so that it overlaps with the toolbar because the
- // top few pixels of the toolbar are not opaque.
- header_height = GetTopInset() + kFrameShadowThickness * 2;
+ // Paint the header so that it overlaps with the top few pixels of the
+ // toolbar because the top few pixels of the toolbar are not opaque.
+ painted_height = GetTopInset() + kFrameShadowThickness * 2;
} else {
- header_height = GetTopInset();
+ painted_height = GetTopInset();
}
- header_painter_->set_header_height(header_height);
+ header_painter_->SetHeaderHeightForPainting(painted_height);
if (avatar_button())
LayoutAvatar();
BrowserNonClientFrameView::Layout();
@@ -346,11 +336,6 @@ gfx::Size BrowserNonClientFrameViewAsh::GetMinimumSize() {
return gfx::Size(min_width, min_client_view_size.height());
}
-void BrowserNonClientFrameViewAsh::OnThemeChanged() {
- BrowserNonClientFrameView::OnThemeChanged();
- header_painter_->OnThemeChanged();
-}
-
///////////////////////////////////////////////////////////////////////////////
// chrome::TabIconViewModel overrides:
@@ -379,7 +364,8 @@ int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
}
int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const {
- return header_painter_->GetRightInset() + kTabstripRightSpacing;
+ return caption_button_container_->GetPreferredSize().width() +
+ kTabstripRightSpacing;
}
bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
@@ -521,68 +507,9 @@ void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
}
void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) {
- if (UsePackagedAppHeaderStyle()) {
- ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ?
- ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE;
- header_painter_->PaintHeaderContentSeparator(canvas, header_mode);
- } else {
- canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
- width(), kClientEdgeThickness),
- ThemeProperties::GetDefaultColor(
- ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
- }
-}
-
-void BrowserNonClientFrameViewAsh::GetFrameImageIdsForTabbedBrowser(
- int* frame_image_id,
- int* frame_overlay_image_id) const {
- *frame_overlay_image_id = 0;
-
- bool is_incognito = !browser_view()->IsRegularOrGuestSession();
- ui::ThemeProvider* tp = GetThemeProvider();
- if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) &&
- !is_incognito) {
- *frame_overlay_image_id = ShouldPaintAsActive() ?
- IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE;
- }
-
- if (ShouldPaintAsActive()) {
- *frame_image_id = is_incognito ?
- IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME;
- } else {
- *frame_image_id = is_incognito ?
- IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE;
- }
-
- if ((frame()->IsMaximized() || frame()->IsFullscreen()) &&
- !tp->HasCustomImage(IDR_THEME_FRAME) &&
- !tp->HasCustomImage(*frame_image_id) &&
- *frame_overlay_image_id == 0) {
- *frame_image_id = IDR_AURA_BROWSER_WINDOW_HEADER_BASE_MAXIMIZED;
- }
-}
-
-int BrowserNonClientFrameViewAsh::GetFrameImageIdForBrowserPopup() const {
- // Browser popups are not themeable.
- if (frame()->IsMaximized() || frame()->IsFullscreen())
- return IDR_AURA_BROWSER_WINDOW_HEADER_BASE_MAXIMIZED;
-
- bool is_incognito = !browser_view()->IsRegularOrGuestSession();
- if (ShouldPaintAsActive()) {
- return is_incognito ?
- IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INCOGNITO_ACTIVE :
- IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_ACTIVE;
- }
- return is_incognito ?
- IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INCOGNITO_INACTIVE :
- IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INACTIVE;
-}
-
-int BrowserNonClientFrameViewAsh::GetFrameImageIdForHostedApp() const {
- if (UsePackagedAppHeaderStyle()) {
- return ShouldPaintAsActive() ?
- IDR_AURA_WINDOW_HEADER_BASE_ACTIVE :
- IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;
- }
- return GetFrameImageIdForBrowserPopup();
+ DCHECK(!UsePackagedAppHeaderStyle());
+ canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
+ width(), kClientEdgeThickness),
+ ThemeProperties::GetDefaultColor(
+ ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
}

Powered by Google App Engine
This is Rietveld 408576698