Index: ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc |
diff --git a/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc b/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc |
index e6ddf6f18d012627a3355cc0262e7bc7f3e6ccb1..4896d88424d626a533078c36c4ea6b95898572ad 100644 |
--- a/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc |
+++ b/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc |
@@ -16,14 +16,38 @@ |
namespace views { |
-const SkColor kTabTitleColor_Inactive = SkColorSetRGB(0x66, 0x66, 0x66); |
-const SkColor kTabTitleColor_Active = SkColorSetRGB(0x20, 0x20, 0x20); |
-const SkColor kTabTitleColor_Pressed = SkColorSetRGB(0x33, 0x33, 0x33); |
-const SkColor kTabTitleColor_Hovered = SkColorSetRGB(0x22, 0x22, 0x22); |
+namespace { |
+struct TabColors { |
+ SkColor title_inactive; |
+ SkColor title_active; |
+ SkColor title_pressed; |
+ SkColor title_hovered; |
+ |
+ SkColor border; |
+}; |
+ |
+TabColors standard_colors = { |
+ SkColorSetRGB(0x66, 0x66, 0x66), |
+ SkColorSetRGB(0x20, 0x20, 0x20), |
+ SkColorSetRGB(0x33, 0x33, 0x33), |
+ SkColorSetRGB(0x22, 0x22, 0x22), |
+ |
+ SkColorSetRGB(0xCC, 0xCC, 0xCC) |
+}; |
+ |
+TabColors chrome_style_colors = { |
+ SkColorSetRGB(0x64, 0x64, 0x64), |
+ SkColorSetRGB(0x00, 0x00, 0x00), |
+ SkColorSetRGB(0x00, 0x00, 0x00), |
+ SkColorSetRGB(0x00, 0x00, 0x00), |
+ |
+ SkColorSetRGB(0xC8, 0xC8, 0xC8) |
+}; |
+} // namespace |
+ |
// TODO(markusheintz): The tab background color should be provided by the |
// NativeTheme. |
const SkColor kTabBackgroundColor_Active = SK_ColorWHITE; |
-const SkColor kTabBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
const SkScalar kTabBorderThickness = 1.0f; |
const SkScalar kTabBorderRadius = 2.0f; |
@@ -31,11 +55,16 @@ class TabStrip; |
class Tab : public View { |
public: |
- Tab(TabStrip* tab_strip, const string16& title, View* contents) |
+ Tab(TabStrip* tab_strip, |
+ const string16& title, |
+ View* contents, |
+ bool use_chrome_style) |
: tab_strip_(tab_strip), |
title_(title), |
contents_(contents), |
- title_color_(kTabTitleColor_Inactive) {} |
+ use_chrome_style_(use_chrome_style), |
+ tab_colors_(use_chrome_style ? chrome_style_colors : standard_colors), |
+ title_color_(tab_colors_.title_inactive) {} |
virtual ~Tab() {} |
static int GetMinimumTabHeight() { |
@@ -57,9 +86,9 @@ class Tab : public View { |
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
virtual gfx::Size GetPreferredSize() OVERRIDE { |
const int kTabMinWidth = 54; |
- gfx::Size ps(GetTabTitleFont().GetStringWidth(title_), |
+ gfx::Size ps(GetTabTitleFont(true).GetStringWidth(title_), |
GetMinimumTabHeight()); |
- ps.Enlarge(30, 10); |
+ ps.Enlarge(use_chrome_style_ ? 20 : 30, 10); |
if (ps.width() < kTabMinWidth) |
ps.set_width(kTabMinWidth); |
return ps; |
@@ -84,19 +113,22 @@ class Tab : public View { |
SkPaint paint; |
paint.setAntiAlias(true); |
paint.setStyle(SkPaint::kStroke_Style); |
- paint.setColor(kTabBorderColor); |
+ paint.setColor(tab_colors_.border); |
paint.setStrokeWidth(kTabBorderThickness * 2); |
canvas->DrawPath(path, paint); |
} |
void PaintTabTitle(gfx::Canvas* canvas, bool selected) { |
- int text_width = GetTabTitleFont().GetStringWidth(title_); |
- int text_height = GetTabTitleFont().GetHeight(); |
+ int text_width = GetTabTitleFont(selected).GetStringWidth(title_); |
+ int text_height = GetTabTitleFont(selected).GetHeight(); |
int text_x = (width() - text_width) / 2; |
int text_y = 5; |
gfx::Rect text_rect(text_x, text_y, text_width, text_height); |
- canvas->DrawStringInt(title_, GetTabTitleFont(), title_color_, text_rect); |
+ canvas->DrawStringInt(title_, |
+ GetTabTitleFont(selected), |
+ title_color_, |
+ text_rect); |
} |
void SetTitleColor(SkColor color) { |
@@ -104,16 +136,27 @@ class Tab : public View { |
SchedulePaint(); |
} |
- const gfx::Font& GetTabTitleFont() { |
- static gfx::Font* title_font = NULL; |
- if (!title_font) |
- title_font = new gfx::Font(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); |
- return *title_font; |
+ const gfx::Font& GetTabTitleFont(bool selected) { |
+ static gfx::Font* title_font_normal = NULL; |
+ static gfx::Font* title_font_bold = NULL; |
+ |
+ if (!title_font_normal) |
+ title_font_normal = new gfx::Font; |
+ if (!title_font_bold) |
+ title_font_bold = |
+ new gfx::Font(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); |
+ |
+ if (!use_chrome_style_) |
+ return *title_font_bold; |
+ else |
+ return selected ? *title_font_bold : *title_font_normal; |
} |
TabStrip* tab_strip_; |
string16 title_; |
View* contents_; |
+ bool use_chrome_style_; |
+ const TabColors& tab_colors_; |
SkColor title_color_; |
DISALLOW_COPY_AND_ASSIGN(Tab); |
@@ -121,23 +164,26 @@ class Tab : public View { |
class TabStrip : public View { |
public: |
- explicit TabStrip(NativeTabbedPaneViews* owner) |
+ TabStrip(NativeTabbedPaneViews* owner, bool use_chrome_style) |
: owner_(owner), |
- selected_tab_(NULL) { |
- const int kCount = 4; |
- // The gradient colors are derived from the tabbed panes used for the |
- // WebUI. |
- SkColor colors[] = { |
+ selected_tab_(NULL), |
+ use_chrome_style_(use_chrome_style) { |
+ if (!use_chrome_style) { |
+ const int kCount = 4; |
+ // The gradient colors are derived from the tabbed panes used for the |
+ // WebUI. |
+ SkColor colors[] = { |
SkColorSetRGB(0xff, 0xff, 0xff), |
SkColorSetRGB(0xff, 0xff, 0xff), |
SkColorSetRGB(0xfa, 0xfa, 0xfa), |
SkColorSetRGB(0xf2, 0xf2, 0xf2) |
- }; |
- // The relative positions of the gradient colors are derived from the |
- // tabbed panes used for the WebUI. |
- SkScalar pos[4] = {0.0f, 0.6f, 0.8f, 1.0f}; |
- set_background(Background::CreateVerticalMultiColorGradientBackground( |
- colors, pos, kCount)); |
+ }; |
+ // The relative positions of the gradient colors are derived from the |
+ // tabbed panes used for the WebUI. |
+ SkScalar pos[4] = {0.0f, 0.6f, 0.8f, 1.0f}; |
+ set_background(Background::CreateVerticalMultiColorGradientBackground( |
+ colors, pos, kCount)); |
+ } |
} |
virtual ~TabStrip() {} |
@@ -172,7 +218,7 @@ class TabStrip : public View { |
return gfx::Size(50, Tab::GetMinimumTabHeight()); |
} |
virtual void Layout() OVERRIDE { |
- const int kTabOffset = 18; |
+ const int kTabOffset = use_chrome_style_ ? 9 : 18; |
int x = kTabOffset; // Layout tabs with an offset to the tabstrip border. |
for (int i = 0; i < child_count(); ++i) { |
gfx::Size ps = child_at(i)->GetPreferredSize(); |
@@ -185,7 +231,8 @@ class TabStrip : public View { |
// Draw the TabStrip border. |
SkPaint paint; |
- paint.setColor(kTabBorderColor); |
+ paint.setColor(use_chrome_style_ ? |
+ chrome_style_colors.border : standard_colors.border); |
paint.setStrokeWidth(kTabBorderThickness); |
SkScalar line_y = SkIntToScalar(height()) - kTabBorderThickness; |
SkScalar line_width = SkIntToScalar(width()); |
@@ -195,12 +242,14 @@ class TabStrip : public View { |
private: |
NativeTabbedPaneViews* owner_; |
View* selected_tab_; |
+ bool use_chrome_style_; |
DISALLOW_COPY_AND_ASSIGN(TabStrip); |
}; |
void Tab::OnSelectedStateChanged(bool selected) { |
- SetTitleColor(selected ? kTabTitleColor_Active : kTabTitleColor_Inactive); |
+ SetTitleColor(selected ? tab_colors_.title_active : |
+ tab_colors_.title_inactive); |
} |
void Tab::OnPaint(gfx::Canvas* canvas) { |
@@ -213,27 +262,27 @@ void Tab::OnPaint(gfx::Canvas* canvas) { |
} |
bool Tab::OnMousePressed(const ui::MouseEvent& event) { |
- SetTitleColor(kTabTitleColor_Pressed); |
+ SetTitleColor(tab_colors_.title_pressed); |
return true; |
} |
void Tab::OnMouseReleased(const ui::MouseEvent& event) { |
- SetTitleColor(kTabTitleColor_Hovered); |
+ SetTitleColor(tab_colors_.title_hovered); |
tab_strip_->SelectTab(this); |
} |
void Tab::OnMouseCaptureLost() { |
- SetTitleColor(kTabTitleColor_Inactive); |
+ SetTitleColor(tab_colors_.title_inactive); |
} |
void Tab::OnMouseEntered(const ui::MouseEvent& event) { |
- SetTitleColor(tab_strip_->IsTabSelected(this) ? kTabTitleColor_Active : |
- kTabTitleColor_Hovered); |
+ SetTitleColor(tab_strip_->IsTabSelected(this) ? tab_colors_.title_active : |
+ tab_colors_.title_hovered); |
} |
void Tab::OnMouseExited(const ui::MouseEvent& event) { |
- SetTitleColor(tab_strip_->IsTabSelected(this) ? kTabTitleColor_Active : |
- kTabTitleColor_Inactive); |
+ SetTitleColor(tab_strip_->IsTabSelected(this) ? tab_colors_.title_active : |
+ tab_colors_.title_inactive); |
} |
// Custom layout manager that takes care of sizing and displaying the tab pages. |
@@ -298,11 +347,14 @@ class TabLayout : public LayoutManager { |
//////////////////////////////////////////////////////////////////////////////// |
// NativeTabbedPaneViews, public: |
-NativeTabbedPaneViews::NativeTabbedPaneViews(TabbedPane* tabbed_pane) |
+NativeTabbedPaneViews::NativeTabbedPaneViews(TabbedPane* tabbed_pane, |
+ bool use_chrome_style) |
: tabbed_pane_(tabbed_pane), |
tab_layout_manager_(new TabLayout), |
- ALLOW_THIS_IN_INITIALIZER_LIST(tab_strip_(new TabStrip(this))), |
- content_view_(new views::View) { |
+ ALLOW_THIS_IN_INITIALIZER_LIST(tab_strip_( |
+ new TabStrip(this, use_chrome_style))), |
+ content_view_(new views::View), |
+ use_chrome_style_(use_chrome_style) { |
AddChildView(tab_strip_); |
AddChildView(content_view_); |
InitControl(); |
@@ -332,7 +384,9 @@ void NativeTabbedPaneViews::AddTabAtIndex(int index, |
contents->set_owned_by_client(); |
contents->SetVisible(false); |
- tab_strip_->AddChildViewAt(new Tab(tab_strip_, title, contents), index); |
+ tab_strip_->AddChildViewAt( |
+ new Tab(tab_strip_, title, contents, use_chrome_style_), |
+ index); |
// Add native tab only if the native control is already created. |
content_view_->AddChildViewAt(contents, index); |