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

Unified Diff: chrome/browser/ui/views/frame/browser_header_painter_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_header_painter_ash.cc
diff --git a/chrome/browser/ui/views/frame/browser_header_painter_ash.cc b/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
index f6fdfafb45429a993fc130f0b2bef32bfbfc1662..a95939d764fcb2bbba9d53c7910149a32730a215 100644
--- a/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_header_painter_ash.cc
@@ -2,64 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/wm/header_painter.h"
-
-#include <vector>
+#include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
#include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
+#include "ash/wm/header_metrics.h"
#include "base/logging.h" // DCHECK
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/views/frame/browser_frame.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
#include "grit/ash_resources.h"
+#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/aura/window.h"
-#include "ui/base/hit_test.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
-#include "ui/gfx/image/image.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
-using aura::Window;
using views::Widget;
namespace {
-// Space between left edge of window and popup window icon.
-const int kIconOffsetX = 9;
-// Height and width of window icon.
-const int kIconSize = 16;
-// Space between the title text and the caption buttons.
-const int kTitleLogoSpacing = 5;
-// Space between window icon and title text.
-const int kTitleIconOffsetX = 5;
-// Space between window edge and title text, when there is no icon.
-const int kTitleNoIconOffsetX = 8;
// Color for the non-maximized window title text.
const SkColor kNonMaximizedWindowTitleTextColor = SkColorSetRGB(40, 40, 40);
// Color for the maximized window title text.
const SkColor kMaximizedWindowTitleTextColor = SK_ColorWHITE;
-// Size of header/content separator line below the header image for non-browser
-// windows.
-const int kHeaderContentSeparatorSize = 1;
-// Color of the active window header/content separator line for non-browser
-// windows.
-const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(180, 180, 182);
-// Color of the inactive window header/content separator line for non-browser
-// windows.
-const SkColor kHeaderContentSeparatorInactiveColor =
- SkColorSetRGB(150, 150, 152);
-// In the pre-Ash era the web content area had a frame along the left edge, so
-// user-generated theme images for the new tab page assume they are shifted
-// right relative to the header. Now that we have removed the left edge frame
-// we need to copy the theme image for the window header from a few pixels
-// inset to preserve alignment with the NTP image, or else we'll break a bunch
-// of existing themes. We do something similar on OS X for the same reason.
-const int kThemeFrameImageInsetX = 5;
// Duration of crossfade animation for activating and deactivating frame.
const int kActivationCrossfadeDurationMs = 200;
@@ -88,8 +62,8 @@ void TileRoundRect(gfx::Canvas* canvas,
// Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top
// corners.
void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
- const gfx::ImageSkia* frame_image,
- const gfx::ImageSkia* frame_overlay_image,
+ const gfx::ImageSkia& frame_image,
+ const gfx::ImageSkia& frame_overlay_image,
const SkPaint& paint,
const gfx::Rect& bounds,
int corner_radius,
@@ -102,31 +76,31 @@ void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
// |frame_overlay_image| using |normal_mode| and then paint the result
// using the unusual mode. We try to avoid this because creating a new
// browser-width canvas is expensive.
- bool fast_path = (!frame_overlay_image ||
+ bool fast_path = (frame_overlay_image.isNull() ||
SkXfermode::IsMode(paint.getXfermode(), normal_mode));
if (fast_path) {
- TileRoundRect(canvas, *frame_image, paint, bounds, corner_radius,
+ TileRoundRect(canvas, frame_image, paint, bounds, corner_radius,
corner_radius, image_inset_x);
- if (frame_overlay_image) {
+ if (!frame_overlay_image.isNull()) {
// Adjust |bounds| such that |frame_overlay_image| is not tiled.
gfx::Rect overlay_bounds = bounds;
overlay_bounds.Intersect(
- gfx::Rect(bounds.origin(), frame_overlay_image->size()));
+ gfx::Rect(bounds.origin(), frame_overlay_image.size()));
int top_left_corner_radius = corner_radius;
int top_right_corner_radius = corner_radius;
if (overlay_bounds.width() < bounds.width() - corner_radius)
top_right_corner_radius = 0;
- TileRoundRect(canvas, *frame_overlay_image, paint, overlay_bounds,
+ TileRoundRect(canvas, frame_overlay_image, paint, overlay_bounds,
top_left_corner_radius, top_right_corner_radius, 0);
}
} else {
gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false);
- temporary_canvas.TileImageInt(*frame_image,
+ temporary_canvas.TileImageInt(frame_image,
image_inset_x, 0,
0, 0,
bounds.width(), bounds.height());
- temporary_canvas.DrawImageInt(*frame_overlay_image, 0, 0);
+ temporary_canvas.DrawImageInt(frame_overlay_image, 0, 0);
TileRoundRect(canvas, gfx::ImageSkia(temporary_canvas.ExtractImageRep()),
paint, bounds, corner_radius, corner_radius, 0);
}
@@ -134,225 +108,141 @@ void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
} // namespace
-namespace ash {
-
///////////////////////////////////////////////////////////////////////////////
-// HeaderPainter, public:
+// BrowserHeaderPainterAsh, public:
-HeaderPainter::HeaderPainter()
+BrowserHeaderPainterAsh::BrowserHeaderPainterAsh()
: frame_(NULL),
- header_view_(NULL),
+ is_tabbed_(false),
+ is_incognito_(false),
+ view_(NULL),
window_icon_(NULL),
caption_button_container_(NULL),
- header_height_(0),
- previous_theme_frame_id_(0),
- previous_theme_frame_overlay_id_(0),
- crossfade_theme_frame_id_(0),
- crossfade_theme_frame_overlay_id_(0) {}
+ painted_height_(0),
+ initial_paint_(true),
+ mode_(MODE_INACTIVE),
+ activation_animation_(new gfx::SlideAnimation(this)) {
+}
-HeaderPainter::~HeaderPainter() {
+BrowserHeaderPainterAsh::~BrowserHeaderPainterAsh() {
}
-void HeaderPainter::Init(
- Style style,
+void BrowserHeaderPainterAsh::Init(
views::Widget* frame,
+ BrowserView* browser_view,
views::View* header_view,
views::View* window_icon,
- FrameCaptionButtonContainerView* caption_button_container) {
+ ash::FrameCaptionButtonContainerView* caption_button_container) {
DCHECK(frame);
+ DCHECK(browser_view);
DCHECK(header_view);
// window_icon may be NULL.
DCHECK(caption_button_container);
- style_ = style;
frame_ = frame;
- header_view_ = header_view;
- window_icon_ = window_icon;
- caption_button_container_ = caption_button_container;
-}
-// static
-gfx::Rect HeaderPainter::GetBoundsForClientView(
- int header_height,
- const gfx::Rect& window_bounds) {
- gfx::Rect client_bounds(window_bounds);
- client_bounds.Inset(0, header_height, 0, 0);
- return client_bounds;
-}
+ is_tabbed_ = browser_view->browser()->is_type_tabbed();
+ is_incognito_ = !browser_view->IsRegularOrGuestSession();
-// static
-gfx::Rect HeaderPainter::GetWindowBoundsForClientBounds(
- int header_height,
- const gfx::Rect& client_bounds) {
- gfx::Rect window_bounds(client_bounds);
- window_bounds.Inset(0, -header_height, 0, 0);
- if (window_bounds.y() < 0)
- window_bounds.set_y(0);
- return window_bounds;
-}
-
-int HeaderPainter::NonClientHitTest(const gfx::Point& point) const {
- gfx::Point point_in_header_view(point);
- views::View::ConvertPointFromWidget(header_view_, &point_in_header_view);
- if (!GetHeaderLocalBounds().Contains(point_in_header_view))
- return HTNOWHERE;
- if (caption_button_container_->visible()) {
- gfx::Point point_in_caption_button_container(point);
- views::View::ConvertPointFromWidget(caption_button_container_,
- &point_in_caption_button_container);
- int component = caption_button_container_->NonClientHitTest(
- point_in_caption_button_container);
- if (component != HTNOWHERE)
- return component;
- }
- // Caption is a safe default.
- return HTCAPTION;
+ view_ = header_view;
+ window_icon_ = window_icon;
+ caption_button_container_ = caption_button_container;
}
-int HeaderPainter::GetMinimumHeaderWidth() const {
+int BrowserHeaderPainterAsh::GetMinimumHeaderWidth() const {
// Ensure we have enough space for the window icon and buttons. We allow
// the title string to collapse to zero width.
- return GetTitleOffsetX() +
+ return GetTitleBounds().x() +
caption_button_container_->GetMinimumSize().width();
}
-int HeaderPainter::GetRightInset() const {
- return caption_button_container_->GetPreferredSize().width();
-}
-
-int HeaderPainter::GetThemeBackgroundXInset() const {
- return kThemeFrameImageInsetX;
-}
+void BrowserHeaderPainterAsh::PaintHeader(gfx::Canvas* canvas, Mode mode) {
James Cook 2014/03/10 17:32:30 Is there any way to share a little more code betwe
+ Mode old_mode = mode_;
+ mode_ = mode;
-void HeaderPainter::PaintHeader(gfx::Canvas* canvas,
- Mode mode,
- int theme_frame_id,
- int theme_frame_overlay_id) {
- bool initial_paint = (previous_theme_frame_id_ == 0);
- if (!initial_paint &&
- (previous_theme_frame_id_ != theme_frame_id ||
- previous_theme_frame_overlay_id_ != theme_frame_overlay_id)) {
+ if (mode_ != old_mode) {
aura::Window* parent = frame_->GetNativeWindow()->parent();
James Cook 2014/03/10 17:32:30 Like maybe this parent-animating check could go in
pkotwicz 2014/03/14 17:56:22 Done. I renamed HeaderMetrics to HeaderPainterUtil
James Cook 2014/03/14 18:27:15 It would be nice if even more of this code could b
- // Don't animate the header if the parent (a workspace) is already
- // animating. Doing so results in continually painting during the animation
- // and gives a slower frame rate.
+ // Don't animate the header if the parent
+ // (e.g. kShellWindowId_DefaultContainer) is already animating. Doing so
+ // results in continually painting during the animation and gives a
+ // slower frame rate.
// TODO(sky): expose a better way to determine this rather than assuming
- // the parent is a workspace.
+ // the parent is a toplevel container.
bool parent_animating = parent &&
(parent->layer()->GetAnimator()->IsAnimatingProperty(
ui::LayerAnimationElement::OPACITY) ||
parent->layer()->GetAnimator()->IsAnimatingProperty(
ui::LayerAnimationElement::VISIBILITY));
- if (!parent_animating) {
- crossfade_animation_.reset(new gfx::SlideAnimation(this));
- crossfade_theme_frame_id_ = previous_theme_frame_id_;
- crossfade_theme_frame_overlay_id_ = previous_theme_frame_overlay_id_;
- crossfade_animation_->SetSlideDuration(kActivationCrossfadeDurationMs);
- crossfade_animation_->Show();
+ if (initial_paint_ || parent_animating) {
+ initial_paint_ = false;
+ if (mode_ == MODE_ACTIVE)
+ activation_animation_->Reset(1);
+ else
+ activation_animation_->Reset(0);
} else {
- crossfade_animation_.reset();
+ activation_animation_->SetSlideDuration(kActivationCrossfadeDurationMs);
+ if (mode_ == MODE_ACTIVE)
+ activation_animation_->Show();
+ else
+ activation_animation_->Hide();
}
}
- ui::ThemeProvider* theme_provider = frame_->GetThemeProvider();
- gfx::ImageSkia* theme_frame = theme_provider->GetImageSkiaNamed(
- theme_frame_id);
- gfx::ImageSkia* theme_frame_overlay = NULL;
- if (theme_frame_overlay_id != 0) {
- theme_frame_overlay = theme_provider->GetImageSkiaNamed(
- theme_frame_overlay_id);
- }
-
- int corner_radius = GetHeaderCornerRadius();
- SkPaint paint;
+ int corner_radius = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
+ 0 : ash::HeaderMetrics::GetTopCornerRadiusWhenRestored();
- if (crossfade_animation_.get() && crossfade_animation_->is_animating()) {
- gfx::ImageSkia* crossfade_theme_frame =
- theme_provider->GetImageSkiaNamed(crossfade_theme_frame_id_);
- gfx::ImageSkia* crossfade_theme_frame_overlay = NULL;
- if (crossfade_theme_frame_overlay_id_ != 0) {
- crossfade_theme_frame_overlay = theme_provider->GetImageSkiaNamed(
- crossfade_theme_frame_overlay_id_);
- }
- if (!crossfade_theme_frame ||
- (crossfade_theme_frame_overlay_id_ != 0 &&
- !crossfade_theme_frame_overlay)) {
- // Reset the animation. This case occurs when the user switches the theme
- // that they are using.
- crossfade_animation_.reset();
- } else {
- int old_alpha = crossfade_animation_->CurrentValueBetween(255, 0);
- int new_alpha = 255 - old_alpha;
+ int active_alpha = activation_animation_->CurrentValueBetween(0, 255);
+ int inactive_alpha = 255 - active_alpha;
- // Draw the old header background, clipping the corners to be rounded.
- paint.setAlpha(old_alpha);
+ SkPaint paint;
+ if (inactive_alpha > 0) {
+ if (active_alpha > 0)
paint.setXfermodeMode(SkXfermode::kPlus_Mode);
- PaintFrameImagesInRoundRect(canvas,
- crossfade_theme_frame,
- crossfade_theme_frame_overlay,
- paint,
- GetHeaderLocalBounds(),
- corner_radius,
- GetThemeBackgroundXInset());
-
- paint.setAlpha(new_alpha);
- }
- }
- // Draw the header background, clipping the corners to be rounded.
- PaintFrameImagesInRoundRect(canvas,
- theme_frame,
- theme_frame_overlay,
- paint,
- GetHeaderLocalBounds(),
- corner_radius,
- GetThemeBackgroundXInset());
+ gfx::ImageSkia inactive_frame_image;
+ gfx::ImageSkia inactive_frame_overlay_image;
+ GetFrameImages(MODE_INACTIVE, &inactive_frame_image,
+ &inactive_frame_overlay_image);
- previous_theme_frame_id_ = theme_frame_id;
- previous_theme_frame_overlay_id_ = theme_frame_overlay_id;
-
- PaintBorder(canvas, mode);
-}
+ paint.setAlpha(inactive_alpha);
+ PaintFrameImagesInRoundRect(canvas,
+ inactive_frame_image,
+ inactive_frame_overlay_image,
+ paint,
+ GetPaintedBounds(),
+ corner_radius,
+ ash::HeaderMetrics::GetThemeBackgroundXInset());
-void HeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas,
- Mode mode) {
- DCHECK_EQ(style_, STYLE_OTHER);
- SkColor color = (mode == MODE_ACTIVE) ?
- kHeaderContentSeparatorColor :
- kHeaderContentSeparatorInactiveColor;
-
- canvas->FillRect(gfx::Rect(0,
- header_height_ - kHeaderContentSeparatorSize,
- header_view_->width(),
- kHeaderContentSeparatorSize),
- color);
-}
+ }
-int HeaderPainter::HeaderContentSeparatorSize() const {
- return kHeaderContentSeparatorSize;
-}
+ if (active_alpha > 0) {
+ gfx::ImageSkia active_frame_image;
+ gfx::ImageSkia active_frame_overlay_image;
+ GetFrameImages(MODE_ACTIVE, &active_frame_image,
+ &active_frame_overlay_image);
+
+ paint.setAlpha(active_alpha);
+ PaintFrameImagesInRoundRect(canvas,
+ active_frame_image,
+ active_frame_overlay_image,
+ paint,
+ GetPaintedBounds(),
+ corner_radius,
+ ash::HeaderMetrics::GetThemeBackgroundXInset());
+ }
-void HeaderPainter::PaintTitleBar(gfx::Canvas* canvas,
- const gfx::FontList& title_font_list) {
- // The window icon is painted by its own views::View.
- views::WidgetDelegate* delegate = frame_->widget_delegate();
- if (delegate && delegate->ShouldShowWindowTitle()) {
- gfx::Rect title_bounds = GetTitleBounds(title_font_list);
- title_bounds.set_x(header_view_->GetMirroredXForRect(title_bounds));
- SkColor title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
- kMaximizedWindowTitleTextColor : kNonMaximizedWindowTitleTextColor;
- canvas->DrawStringRectWithFlags(delegate->GetWindowTitle(),
- title_font_list,
- title_color,
- title_bounds,
- gfx::Canvas::NO_SUBPIXEL_RENDERING);
+ if (!frame_->IsMaximized() && !frame_->IsFullscreen())
+ PaintBorderForRestoredWindow(canvas);
+ if (frame_->widget_delegate() &&
+ frame_->widget_delegate()->ShouldShowWindowTitle()) {
+ PaintTitleBar(canvas);
}
}
-void HeaderPainter::LayoutHeader() {
- // Purposefully set |header_height_| to an invalid value. We cannot use
- // |header_height_| because the computation of |header_height_| may depend
+void BrowserHeaderPainterAsh::LayoutHeader() {
+ // Purposefully set |painted_height_| to an invalid value. We cannot use
+ // |painted_height_| because the computation of |painted_height_| may depend
// on having laid out the window controls.
- header_height_ = -1;
+ painted_height_ = -1;
UpdateCaptionButtonImages();
caption_button_container_->Layout();
@@ -360,7 +250,7 @@ void HeaderPainter::LayoutHeader() {
gfx::Size caption_button_container_size =
caption_button_container_->GetPreferredSize();
caption_button_container_->SetBounds(
- header_view_->width() - caption_button_container_size.width(),
+ view_->width() - caption_button_container_size.width(),
0,
caption_button_container_size.width(),
caption_button_container_size.height());
@@ -368,260 +258,224 @@ void HeaderPainter::LayoutHeader() {
if (window_icon_) {
// Vertically center the window icon with respect to the caption button
// container.
- int icon_offset_y =
- GetCaptionButtonContainerCenterY() - window_icon_->height() / 2;
- window_icon_->SetBounds(kIconOffsetX, icon_offset_y, kIconSize, kIconSize);
+ int icon_size = ash::HeaderMetrics::GetIconSize();
+ int icon_offset_y = caption_button_container_->y() +
+ (caption_button_container_->height() - icon_size) / 2;
+ window_icon_->SetBounds(ash::HeaderMetrics::GetIconXOffset(), icon_offset_y,
+ icon_size, icon_size);
}
}
-void HeaderPainter::SchedulePaintForTitle(
- const gfx::FontList& title_font_list) {
- header_view_->SchedulePaintInRect(GetTitleBounds(title_font_list));
+int BrowserHeaderPainterAsh::GetHeaderHeightForPainting() const {
+ return painted_height_;
}
-void HeaderPainter::OnThemeChanged() {
- // We do not cache the images for |previous_theme_frame_id_| and
- // |previous_theme_frame_overlay_id_|. Changing the theme changes the images
- // returned from ui::ThemeProvider for |previous_theme_frame_id_|
- // and |previous_theme_frame_overlay_id_|. Reset the image ids to prevent
- // starting a crossfade animation with these images.
- previous_theme_frame_id_ = 0;
- previous_theme_frame_overlay_id_ = 0;
-
- if (crossfade_animation_.get() && crossfade_animation_->is_animating()) {
- crossfade_animation_.reset();
- header_view_->SchedulePaintInRect(GetHeaderLocalBounds());
- }
+void BrowserHeaderPainterAsh::SetHeaderHeightForPainting(int height) {
+ painted_height_ = height;
+}
+
+void BrowserHeaderPainterAsh::SchedulePaintForTitle() {
+ view_->SchedulePaintInRect(GetTitleBounds());
}
///////////////////////////////////////////////////////////////////////////////
// gfx::AnimationDelegate overrides:
-void HeaderPainter::AnimationProgressed(const gfx::Animation* animation) {
- header_view_->SchedulePaintInRect(GetHeaderLocalBounds());
+void BrowserHeaderPainterAsh::AnimationProgressed(
+ const gfx::Animation* animation) {
+ view_->SchedulePaintInRect(GetPaintedBounds());
}
///////////////////////////////////////////////////////////////////////////////
-// HeaderPainter, private:
-
-void HeaderPainter::PaintBorder(gfx::Canvas* canvas, Mode mode) {
- if (frame_->IsMaximized() ||
- frame_->IsFullscreen() ||
- (style_ == STYLE_OTHER && mode == MODE_ACTIVE)) {
- return;
- }
-
- gfx::ImageSkia top_left_corner;
- gfx::ImageSkia top_right_corner;
- gfx::ImageSkia top_edge;
- gfx::ImageSkia left_edge;
- gfx::ImageSkia right_edge;
- gfx::ImageSkia bottom_edge;
+// BrowserHeaderPainterAsh, private:
+void BrowserHeaderPainterAsh::PaintBorderForRestoredWindow(
+ gfx::Canvas* canvas) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- if (style_ == STYLE_BROWSER) {
- top_left_corner = *rb.GetImageSkiaNamed(
- IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT);
- top_right_corner = *rb.GetImageSkiaNamed(
- IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT);
- top_edge = *rb.GetImageSkiaNamed(IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP);
- left_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT);
- right_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT);
- } else {
- top_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP);
- left_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT);
- right_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT);
- bottom_edge = *rb.GetImageSkiaNamed(
- IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM);
- }
-
- DCHECK(!top_edge.isNull());
- DCHECK(!left_edge.isNull());
- DCHECK(!right_edge.isNull());
+ gfx::ImageSkia top_left_corner = *rb.GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT);
+ gfx::ImageSkia top_right_corner = *rb.GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT);
+ gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP);
+ gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT);
+ gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT);
int top_left_width = top_left_corner.width();
int top_left_height = top_left_corner.height();
- if (!top_left_corner.isNull()) {
- canvas->DrawImageInt(top_left_corner, 0, 0);
- }
+ canvas->DrawImageInt(top_left_corner, 0, 0);
int top_right_height = top_right_corner.height();
- if (!top_right_corner.isNull()) {
- canvas->DrawImageInt(top_right_corner,
- header_view_->width() - top_right_corner.width(),
- top_right_height);
- }
+ canvas->DrawImageInt(top_right_corner,
+ view_->width() - top_right_corner.width(),
+ 0);
canvas->TileImageInt(top_edge,
top_left_width,
0,
- header_view_->width() - top_left_width - top_right_corner.width(),
+ view_->width() - top_left_width - top_right_corner.width(),
top_edge.height());
- // TODO(pkotwicz): Compute |bottom| more accurately. The computation is
- // inaccurate for browser windows.
- int bottom = header_height_ - kHeaderContentSeparatorSize;
- int bottom_height = bottom_edge.height();
- if (!bottom_edge.isNull()) {
- canvas->TileImageInt(bottom_edge,
- 0, bottom - bottom_height,
- header_view_->width(), bottom_height);
- }
-
- int left_edge_height = bottom - bottom_height - top_left_height;
canvas->TileImageInt(left_edge,
0, top_left_height,
- left_edge.width(), left_edge_height);
+ left_edge.width(), painted_height_ - top_left_height);
- int right_edge_height = bottom - bottom_height - top_right_height;
canvas->TileImageInt(right_edge,
- header_view_->width() - right_edge.width(),
+ view_->width() - right_edge.width(),
top_right_height,
right_edge.width(),
- right_edge_height);
+ painted_height_ - top_right_height);
}
-void HeaderPainter::UpdateCaptionButtonImages() {
- if (style_ == STYLE_BROWSER) {
- if (frame_->IsMaximized() || frame_->IsFullscreen()) {
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
- } else {
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
- IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
- }
+void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) {
+ // The window icon is painted by its own views::View.
+ gfx::Rect title_bounds = GetTitleBounds();
+ title_bounds.set_x(view_->GetMirroredXForRect(title_bounds));
+ SkColor title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
+ kMaximizedWindowTitleTextColor : kNonMaximizedWindowTitleTextColor;
+ canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(),
+ BrowserFrame::GetTitleFontList(),
+ title_color,
+ title_bounds,
+ gfx::Canvas::NO_SUBPIXEL_RENDERING);
+}
+
+void BrowserHeaderPainterAsh::GetFrameImages(
+ Mode mode,
+ gfx::ImageSkia* frame_image,
+ gfx::ImageSkia* frame_overlay_image) const {
+ if (is_tabbed_) {
+ GetFrameImagesForTabbedBrowser(mode, frame_image, frame_overlay_image);
} else {
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MINIMIZE,
- IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE,
- IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
- IDR_AURA_WINDOW_CONTROL_ICON_SIZE,
- IDR_AURA_WINDOW_CONTROL_ICON_SIZE_I,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_CLOSE,
- IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
- IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_I,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
-
- // There is no dedicated icon for the snap-left and snap-right buttons
- // when |frame_| is inactive because they should never be visible while
- // |frame_| is inactive.
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_LEFT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
- caption_button_container_->SetButtonImages(
- CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
- IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
+ *frame_image = GetFrameImageForNonTabbedBrowser(mode);
+ *frame_overlay_image = gfx::ImageSkia();
}
}
-gfx::Rect HeaderPainter::GetHeaderLocalBounds() const {
- return gfx::Rect(header_view_->width(), header_height_);
-}
+void BrowserHeaderPainterAsh::GetFrameImagesForTabbedBrowser(
+ Mode mode,
+ gfx::ImageSkia* frame_image,
+ gfx::ImageSkia* frame_overlay_image) const {
+ int frame_image_id = 0;
+ int frame_overlay_image_id = 0;
+
+ ui::ThemeProvider* tp = frame_->GetThemeProvider();
+ if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && !is_incognito_) {
+ frame_overlay_image_id = (mode == MODE_ACTIVE) ?
+ IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE;
+ }
+
+ if (mode == MODE_ACTIVE) {
+ 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;
+ }
-int HeaderPainter::GetTitleOffsetX() const {
- return window_icon_ ?
- window_icon_->bounds().right() + kTitleIconOffsetX :
- kTitleNoIconOffsetX;
+ if ((frame_->IsMaximized() || frame_->IsFullscreen()) &&
+ !tp->HasCustomImage(IDR_THEME_FRAME) &&
+ !tp->HasCustomImage(frame_image_id) &&
+ frame_overlay_image_id == 0) {
+ *frame_image = *tp->GetImageSkiaNamed(
+ IDR_AURA_BROWSER_WINDOW_HEADER_BASE_MAXIMIZED);
+ } else {
+ *frame_image = *tp->GetImageSkiaNamed(frame_image_id);
+ }
+
+ *frame_overlay_image = (frame_overlay_image_id == 0) ?
+ gfx::ImageSkia() : *tp->GetImageSkiaNamed(frame_overlay_image_id);
}
-int HeaderPainter::GetCaptionButtonContainerCenterY() const {
- return caption_button_container_->y() +
- caption_button_container_->height() / 2;
+gfx::ImageSkia BrowserHeaderPainterAsh::GetFrameImageForNonTabbedBrowser(
+ Mode mode) const {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ if (frame_->IsMaximized() || frame_->IsFullscreen())
+ return *rb.GetImageSkiaNamed(IDR_AURA_BROWSER_WINDOW_HEADER_BASE_MAXIMIZED);
+
+ if (mode == MODE_ACTIVE) {
+ return *rb.GetImageSkiaNamed(is_incognito_ ?
+ IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INCOGNITO_ACTIVE :
+ IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_ACTIVE);
+ }
+ return *rb.GetImageSkiaNamed(is_incognito_ ?
+ IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INCOGNITO_INACTIVE :
+ IDR_AURA_BROWSER_WINDOW_HEADER_BASE_RESTORED_INACTIVE);
}
-int HeaderPainter::GetHeaderCornerRadius() const {
- bool square_corners = (frame_->IsMaximized() || frame_->IsFullscreen());
- const int kCornerRadius = 2;
- return square_corners ? 0 : kCornerRadius;
+void BrowserHeaderPainterAsh::UpdateCaptionButtonImages() {
+ if (frame_->IsMaximized() || frame_->IsFullscreen()) {
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
+ } else {
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
+ caption_button_container_->SetButtonImages(
+ ash::CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
+ IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
+ }
}
-gfx::Rect HeaderPainter::GetTitleBounds(const gfx::FontList& title_font_list) {
- int title_x = GetTitleOffsetX();
- // Center the text with respect to the caption button container. This way it
- // adapts to the caption button height and aligns exactly with the window
- // icon. Don't use |window_icon_| for this computation as it may be NULL.
- int title_y =
- GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2;
- return gfx::Rect(
- title_x,
- std::max(0, title_y),
- std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x),
- title_font_list.GetHeight());
+gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const {
+ return gfx::Rect(view_->width(), painted_height_);
}
-} // namespace ash
+gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const {
+ return ash::HeaderMetrics::GetTitleBounds(window_icon_,
+ caption_button_container_, BrowserFrame::GetTitleFontList());
+}

Powered by Google App Engine
This is Rietveld 408576698