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

Unified Diff: chrome/browser/ui/panels/panel_browser_frame_view.cc

Issue 8664021: Update Panel UI looks on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_frame_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/panels/panel_browser_frame_view.cc
diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc
index 647435f6014df1edc3ea2641f9e15dfddb0cd60d..f39237a15da161ae870be2fb94e8a234a647be13 100644
--- a/chrome/browser/ui/panels/panel_browser_frame_view.cc
+++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc
@@ -8,6 +8,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/themes/theme_service.h"
+#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_browser_view.h"
#include "chrome/browser/ui/panels/panel_manager.h"
@@ -27,6 +28,7 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/path.h"
#include "ui/gfx/screen.h"
+#include "ui/gfx/skia_util.h"
#include "ui/views/widget/widget_delegate.h"
#include "views/controls/button/image_button.h"
#include "views/controls/button/menu_button.h"
@@ -41,24 +43,54 @@ namespace {
// The height in pixels of the titlebar.
const int kTitlebarHeight = 24;
-// The thickness in pixels of the frame border.
-const int kFrameBorderThickness = 1;
+// The thickness in pixels of the border.
+const int kBorderThickness = 1;
-// The spacing in pixels between the icon and the border/text.
-const int kIconSpacing = 4;
+// No client edge is present.
+const int kPanelClientEdgeThickness = 0;
+
+// The spacing in pixels between the icon and the left border.
+const int kIconAndBorderSpacing = 4;
// The height and width in pixels of the icon.
const int kIconSize = 16;
-// The spacing in pixels between buttons or the button and the adjacent control.
-const int kButtonSpacing = 6;
+// The spacing in pixels between the title and the icon on the left, or the
+// button on the right.
+const int kTitleSpacing = 8;
+
+// The spacing in pixels between the close button and the right border.
+const int kCloseButtonAndBorderSpacing = 8;
+
+// The spacing in pixels between the close button and the settings button.
+const int kSettingsButtonAndCloseButtonSpacing = 8;
// This value is experimental and subjective.
const int kUpdateSettingsVisibilityAnimationMs = 120;
-// Colors used in painting the titlebar for drawing attention.
-const SkColor kBackgroundColorForAttention = 0xfffa983a;
-const SkColor kTitleTextColorForAttention = SK_ColorWHITE;
+// Colors used to draw active titlebar under default theme.
+const SkColor kActiveTitleTextDefaultColor = SK_ColorBLACK;
+const SkColor kActiveBackgroundDefaultColorStart = 0xfff0f8fa;
+const SkColor kActiveBackgroundDefaultColorEnd = 0xffd1e2ed;
+
+// Colors used to draw inactive titlebar under default theme.
+const SkColor kInactiveTitleTextDefaultColor = 0xc0000000;
+const SkColor kInactiveBackgroundDefaultColorStart = 0xffffffff;
+const SkColor kInactiveBackgroundDefaultColorEnd = 0xffe7edf1;
+
+// Alpha value used in drawing inactive titlebar under default theme.
+const U8CPU kInactiveAlphaBlending = 0xc0;
+
+// Colors used to draw titlebar for drawing attention regardless of the theme.
+const SkColor kAttentionTitleTextColor = SK_ColorWHITE;
+const SkColor kAttentionBackgroundColorStart = 0xffffab57;
+const SkColor kAttentionBackgroundColorEnd = 0xfff59338;
+
+// Color used to draw the border.
+const SkColor kBorderColor = 0xc0000000;
+
+// Color used to draw the divider line between the titlebar and the client area.
+const SkColor kDividerColor = 0xffb5b5b5;
struct ButtonResources {
SkBitmap* normal_image;
@@ -104,9 +136,21 @@ struct EdgeResources {
ButtonResources settings_button_resources;
ButtonResources close_button_resources;
EdgeResources frame_edges;
-EdgeResources client_edges;
gfx::Font* title_font = NULL;
-SkBitmap* background_bitmap_for_attention = NULL;
+SkPaint active_background_default_paint;
Dmitry Titov 2011/11/29 04:04:03 I wonder if this is a good thing to have objects w
jianli 2011/11/29 19:30:15 Done.
+SkPaint inactive_background_default_paint;
+SkPaint attention_background_paint;
+
+void InitializeGradientPaint(SkPaint* paint,
Dmitry Titov 2011/11/29 04:04:03 why not return the SkPaint*, especially if statics
jianli 2011/11/29 19:30:15 I still need this to do the delay initialization w
+ SkColor start_color,
+ SkColor end_color) {
+ SkShader* shader = gfx::CreateGradientShader(
+ 0, kTitlebarHeight, start_color, end_color);
+ paint->setStyle(SkPaint::kFill_Style);
+ paint->setAntiAlias(true);
+ paint->setShader(shader);
+ shader->unref();
+}
void LoadImageResources() {
settings_button_resources.SetResources(
@@ -120,12 +164,6 @@ void LoadImageResources() {
IDR_WINDOW_TOP_RIGHT_CORNER, IDR_WINDOW_RIGHT_SIDE,
IDR_PANEL_BOTTOM_RIGHT_CORNER, IDR_WINDOW_BOTTOM_CENTER,
IDR_PANEL_BOTTOM_LEFT_CORNER, IDR_WINDOW_LEFT_SIDE);
-
- client_edges.SetResources(
- IDR_APP_TOP_LEFT, IDR_APP_TOP_CENTER,
- IDR_APP_TOP_RIGHT, IDR_CONTENT_RIGHT_SIDE,
- IDR_CONTENT_BOTTOM_RIGHT_CORNER, IDR_CONTENT_BOTTOM_CENTER,
- IDR_CONTENT_BOTTOM_LEFT_CORNER, IDR_CONTENT_LEFT_SIDE);
}
void EnsureResourcesInitialized() {
@@ -135,14 +173,17 @@ void EnsureResourcesInitialized() {
resources_initialized = true;
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- title_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
-
- // Creates a bitmap of the specified color.
- background_bitmap_for_attention = new SkBitmap();
- background_bitmap_for_attention->setConfig(
- SkBitmap::kARGB_8888_Config, 16, 16);
- background_bitmap_for_attention->allocPixels();
- background_bitmap_for_attention->eraseColor(kBackgroundColorForAttention);
+ title_font = new gfx::Font(rb.GetFont(ResourceBundle::BoldFont));
+
+ InitializeGradientPaint(&active_background_default_paint,
+ kActiveBackgroundDefaultColorStart,
+ kActiveBackgroundDefaultColorEnd);
+ InitializeGradientPaint(&inactive_background_default_paint,
+ kInactiveBackgroundDefaultColorStart,
+ kInactiveBackgroundDefaultColorEnd);
+ InitializeGradientPaint(&attention_background_paint,
+ kAttentionBackgroundColorStart,
+ kAttentionBackgroundColorEnd);
LoadImageResources();
}
@@ -340,33 +381,19 @@ int PanelBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
void PanelBrowserFrameView::GetWindowMask(const gfx::Size& size,
gfx::Path* window_mask) {
- // For panel, the window shape is rectangle with top-left and top-right
- // corners rounded.
- if (size.height() <= Panel::kMinimizedPanelHeight) {
- // For minimize panel, we need to produce the window mask applicable to
- // the 3-pixel lines.
- window_mask->moveTo(0, SkIntToScalar(size.height()));
- window_mask->lineTo(0, 1);
- window_mask->lineTo(1, 0);
- window_mask->lineTo(SkIntToScalar(size.width()) - 1, 0);
- window_mask->lineTo(SkIntToScalar(size.width()), 1);
- window_mask->lineTo(SkIntToScalar(size.width()),
- SkIntToScalar(size.height()));
- } else {
- window_mask->moveTo(0, 3);
- window_mask->lineTo(1, 2);
- window_mask->lineTo(1, 1);
- window_mask->lineTo(2, 1);
- window_mask->lineTo(3, 0);
- window_mask->lineTo(SkIntToScalar(size.width() - 3), 0);
- window_mask->lineTo(SkIntToScalar(size.width() - 2), 1);
- window_mask->lineTo(SkIntToScalar(size.width() - 1), 1);
- window_mask->lineTo(SkIntToScalar(size.width() - 1), 2);
- window_mask->lineTo(SkIntToScalar(size.width()), 3);
- window_mask->lineTo(SkIntToScalar(size.width()),
- SkIntToScalar(size.height()));
- window_mask->lineTo(0, SkIntToScalar(size.height()));
- }
+ window_mask->moveTo(0, 3);
+ window_mask->lineTo(1, 2);
+ window_mask->lineTo(1, 1);
+ window_mask->lineTo(2, 1);
+ window_mask->lineTo(3, 0);
+ window_mask->lineTo(SkIntToScalar(size.width() - 3), 0);
+ window_mask->lineTo(SkIntToScalar(size.width() - 2), 1);
+ window_mask->lineTo(SkIntToScalar(size.width() - 1), 1);
+ window_mask->lineTo(SkIntToScalar(size.width() - 1), 2);
+ window_mask->lineTo(SkIntToScalar(size.width() - 1), 3);
+ window_mask->lineTo(SkIntToScalar(size.width()),
+ SkIntToScalar(size.height()));
+ window_mask->lineTo(0, SkIntToScalar(size.height()));
window_mask->close();
}
@@ -390,7 +417,6 @@ void PanelBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
UpdateControlStyles(paint_state);
PaintFrameBorder(canvas);
- PaintClientEdge(canvas);
}
void PanelBrowserFrameView::OnThemeChanged() {
@@ -398,7 +424,7 @@ void PanelBrowserFrameView::OnThemeChanged() {
}
gfx::Size PanelBrowserFrameView::GetMinimumSize() {
- // This makes the panel be able to shrink to very small, like 3-pixel lines.
+ // This makes the panel be able to shrink to very small, like 4-pixel lines.
// Since the panel cannot be resized by the user, we do not need to enforce
// the minimum size.
return gfx::Size();
@@ -413,7 +439,7 @@ void PanelBrowserFrameView::Layout() {
// Layout the close button.
gfx::Size close_button_size = close_button_->GetPreferredSize();
close_button_->SetBounds(
- width() - kFrameBorderThickness - kButtonSpacing -
+ width() - kBorderThickness - kCloseButtonAndBorderSpacing -
close_button_size.width(),
(NonClientTopBorderHeight() - close_button_size.height()) / 2,
close_button_size.width(),
@@ -422,7 +448,8 @@ void PanelBrowserFrameView::Layout() {
// Layout the settings button.
gfx::Size settings_button_size = settings_button_->GetPreferredSize();
settings_button_->SetBounds(
- close_button_->x() - kButtonSpacing - settings_button_size.width(),
+ close_button_->x() - kSettingsButtonAndCloseButtonSpacing -
+ settings_button_size.width(),
(NonClientTopBorderHeight() - settings_button_size.height()) / 2,
settings_button_size.width(),
settings_button_size.height());
@@ -440,18 +467,18 @@ void PanelBrowserFrameView::Layout() {
// Layout the icon.
int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2;
title_icon_->SetBounds(
- kFrameBorderThickness + kIconSpacing,
+ kBorderThickness + kIconAndBorderSpacing,
icon_y,
kIconSize,
kIconSize);
// Layout the title.
- int title_x = title_icon_->bounds().right() + kIconSpacing;
+ int title_x = title_icon_->bounds().right() + kTitleSpacing;
int title_height = BrowserFrame::GetTitleFont().GetHeight();
title_label_->SetBounds(
title_x,
icon_y + ((kIconSize - title_height - 1) / 2),
- std::max(0, settings_button_->x() - kButtonSpacing - title_x),
+ std::max(0, settings_button_->x() - kTitleSpacing - title_x),
title_height);
// Calculate the client area bounds.
@@ -553,11 +580,11 @@ void PanelBrowserFrameView::AnimationCanceled(const ui::Animation* animation) {
}
int PanelBrowserFrameView::NonClientBorderThickness() const {
- return kFrameBorderThickness + kClientEdgeThickness;
+ return kBorderThickness + kPanelClientEdgeThickness;
}
int PanelBrowserFrameView::NonClientTopBorderHeight() const {
- return kFrameBorderThickness + kTitlebarHeight + kClientEdgeThickness;
+ return kBorderThickness + kTitlebarHeight + kPanelClientEdgeThickness;
}
gfx::Size PanelBrowserFrameView::NonClientAreaSize() const {
@@ -565,15 +592,37 @@ gfx::Size PanelBrowserFrameView::NonClientAreaSize() const {
NonClientTopBorderHeight() + NonClientBorderThickness());
}
+bool PanelBrowserFrameView::UsingDefaultTheme() const {
+ ThemeService* theme_service = ThemeServiceFactory::GetForProfile(
+ panel_browser_view_->panel()->browser()->profile());
+ return theme_service->UsingDefaultTheme();
+}
+
+SkColor PanelBrowserFrameView::GetDefaultTitleColor(
+ PaintState paint_state) const {
+ switch (paint_state) {
+ case PAINT_AS_INACTIVE:
+ return kActiveTitleTextDefaultColor;
+ case PAINT_AS_ACTIVE:
+ return kInactiveTitleTextDefaultColor;
+ case PAINT_FOR_ATTENTION:
+ return kAttentionTitleTextColor;
+ default:
+ NOTREACHED();
+ return SkColor();
+ }
+}
+
SkColor PanelBrowserFrameView::GetTitleColor(PaintState paint_state) const {
switch (paint_state) {
case PAINT_AS_INACTIVE:
- return GetThemeProvider()->GetColor(
- ThemeService::COLOR_BACKGROUND_TAB_TEXT);
+ return SkColorSetA(
+ GetThemeProvider()->GetColor(ThemeService::COLOR_BACKGROUND_TAB_TEXT),
+ kInactiveAlphaBlending);
case PAINT_AS_ACTIVE:
return GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT);
case PAINT_FOR_ATTENTION:
- return kTitleTextColorForAttention;
+ return kAttentionTitleTextColor;
default:
NOTREACHED();
return SkColor();
@@ -584,6 +633,21 @@ gfx::Font* PanelBrowserFrameView::GetTitleFont() const {
return title_font;
}
+SkPaint* PanelBrowserFrameView::GetDefaultFrameTheme(
+ PaintState paint_state) const {
+ switch (paint_state) {
+ case PAINT_AS_INACTIVE:
+ return &inactive_background_default_paint;
+ case PAINT_AS_ACTIVE:
+ return &active_background_default_paint;
+ case PAINT_FOR_ATTENTION:
+ return &attention_background_paint;
+ default:
+ NOTREACHED();
+ return NULL;
+ }
+}
+
SkBitmap* PanelBrowserFrameView::GetFrameTheme(PaintState paint_state) const {
switch (paint_state) {
case PAINT_AS_INACTIVE:
@@ -591,7 +655,8 @@ SkBitmap* PanelBrowserFrameView::GetFrameTheme(PaintState paint_state) const {
case PAINT_AS_ACTIVE:
return GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR);
case PAINT_FOR_ATTENTION:
- return background_bitmap_for_attention;
+ // Background color for drawing attention is same regardless of the
+ // theme. GetDefaultFrameTheme should be used.
default:
NOTREACHED();
return NULL;
@@ -615,14 +680,14 @@ void PanelBrowserFrameView::UpdateControlStyles(PaintState paint_state) {
}
void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) {
- SkBitmap* theme_frame = GetFrameTheme(paint_state_);
-
- // Draw the theme frame.
- canvas->TileImageInt(*theme_frame, 0, 0, width(), height());
-
- // No need to paint other stuff if panel is minimized.
- if (height() <= Panel::kMinimizedPanelHeight)
- return;
+ // Paint the background.
+ if (paint_state_ == PAINT_FOR_ATTENTION || UsingDefaultTheme()) {
+ SkPaint* paint = GetDefaultFrameTheme(paint_state_);
+ canvas->DrawRectInt(0, 0, width(), kTitlebarHeight, *paint);
+ } else {
+ SkBitmap* bitmap = GetFrameTheme(paint_state_);
+ canvas->TileImageInt(*bitmap, 0, 0, width(), kTitlebarHeight);
+ }
// Draw the top border.
canvas->DrawBitmapInt(*(frame_edges.top_left), 0, 0);
@@ -661,52 +726,12 @@ void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) {
frame_edges.left->width(),
height() - frame_edges.top_left->height() -
frame_edges.bottom_left->height());
-}
-
-void PanelBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) {
- int client_area_top = client_view_bounds_.y();
- // No need to paint other stuff if panel is minimized.
- if (height() <= Panel::kMinimizedPanelHeight)
- return;
-
- // Draw the top edge.
- int top_edge_y = client_area_top - client_edges.top->height();
- canvas->DrawBitmapInt(
- *(client_edges.top_left),
- client_view_bounds_.x() - client_edges.top_left->width(),
- top_edge_y);
- canvas->TileImageInt(
- *(client_edges.top), client_view_bounds_.x(), top_edge_y,
- client_view_bounds_.width(), client_edges.top->height());
- canvas->DrawBitmapInt(
- *(client_edges.top_right), client_view_bounds_.right(), top_edge_y);
-
- // Draw the right edge.
- int client_area_bottom =
- std::max(client_area_top, client_view_bounds_.bottom());
- int client_area_height = client_area_bottom - client_area_top;
- canvas->TileImageInt(
- *(client_edges.right), client_view_bounds_.right(), client_area_top,
- client_edges.right->width(), client_area_height);
-
- // Draw the bottom edge.
- canvas->DrawBitmapInt(
- *(client_edges.bottom_right), client_view_bounds_.right(),
- client_area_bottom);
- canvas->TileImageInt(
- *(client_edges.bottom), client_view_bounds_.x(), client_area_bottom,
- client_view_bounds_.width(), client_edges.bottom_right->height());
- canvas->DrawBitmapInt(
- *(client_edges.bottom_left),
- client_view_bounds_.x() - client_edges.bottom_left->width(),
- client_area_bottom);
-
- // Draw the left edge.
- canvas->TileImageInt(
- *(client_edges.left),
- client_view_bounds_.x() - client_edges.left->width(),
- client_area_top, client_edges.left->width(), client_area_height);
+ // Draw the divider between the titlebar and the client area.
+ if (height() > kTitlebarHeight) {
+ canvas->DrawRectInt(kDividerColor, kBorderThickness, kTitlebarHeight,
+ width() - 1 - 2 * kBorderThickness, kBorderThickness);
+ }
}
string16 PanelBrowserFrameView::GetTitleText() const {
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698