Commit e8424704 authored by mirandac@chromium.org's avatar mirandac@chromium.org

Theme window control buttons.

BUG= http://crbug.com/14579
TEST= Install a theme with themed window control buttons.  Observe that WCB's are themed.


Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=19758
Review URL: http://codereview.chromium.org/150041

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20028 0039d316-1c4b-4281-b951-d872f2087c98
parent be715074
...@@ -284,13 +284,20 @@ ...@@ -284,13 +284,20 @@
<include name="IDR_THEME_FRAME_OVERLAY" file="notused.png" type="BINDATA" /> <include name="IDR_THEME_FRAME_OVERLAY" file="notused.png" type="BINDATA" />
<include name="IDR_THEME_BUTTON_BACKGROUND" file="notused.png" type="BINDATA" /> <include name="IDR_THEME_BUTTON_BACKGROUND" file="notused.png" type="BINDATA" />
<include name="IDR_THEME_NTP_ATTRIBUTION" file="notused.png" type="BINDATA" /> <include name="IDR_THEME_NTP_ATTRIBUTION" file="notused.png" type="BINDATA" />
<include name="IDR_THEME_WINDOW_CONTROL_BACKGROUND" file="notused.png" type="BINDATA" />
<include name="IDR_FORWARD_MASK" file="forward_mask.png" type="BINDATA" /> <include name="IDR_FORWARD_MASK" file="forward_mask.png" type="BINDATA" />
<include name="IDR_BACK_MASK" file="back_mask.png" type="BINDATA" /> <include name="IDR_BACK_MASK" file="back_mask.png" type="BINDATA" />
<include name="IDR_BUTTON_MASK" file="button_mask.png" type="BINDATA" /> <include name="IDR_BUTTON_MASK" file="button_mask.png" type="BINDATA" />
<include name="IDR_STAR_MASK" file="star_mask.png" type="BINDATA" /> <include name="IDR_STAR_MASK" file="star_mask.png" type="BINDATA" />
<include name="IDR_GO_MASK" file="go_mask.png" type="BINDATA" /> <include name="IDR_GO_MASK" file="go_mask.png" type="BINDATA" />
<include name="IDR_NEWTAB_BUTTON_MASK" file="newtab_button_mask.png" type="BINDATA" />
<include name="IDR_CLOSE_BUTTON_MASK" file="close_button_mask.png" type="BINDATA" />
<include name="IDR_RESTORE_BUTTON_MASK" file="restore_button_mask.png" type="BINDATA" />
<include name="IDR_MINIMIZE_BUTTON_MASK" file="minimize_button_mask.png" type="BINDATA" />
<include name="IDR_MAXIMIZE_BUTTON_MASK" file="maximize_button_mask.png" type="BINDATA" />
<if expr="pp_ifdef('_google_chrome')"> <if expr="pp_ifdef('_google_chrome')">
<include name="IDR_ABOUT_BACKGROUND" file="google_chrome/about_background.png" type="BINDATA" /> <include name="IDR_ABOUT_BACKGROUND" file="google_chrome/about_background.png" type="BINDATA" />
<include name="IDR_ABOUT_BACKGROUND_RTL" file="google_chrome/about_background_rtl.png" type="BINDATA" /> <include name="IDR_ABOUT_BACKGROUND_RTL" file="google_chrome/about_background_rtl.png" type="BINDATA" />
......
...@@ -1420,6 +1420,7 @@ void BrowserView::Init() { ...@@ -1420,6 +1420,7 @@ void BrowserView::Init() {
tabstrip_ = new TabStrip(browser_->tabstrip_model()); tabstrip_ = new TabStrip(browser_->tabstrip_model());
tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP));
AddChildView(tabstrip_); AddChildView(tabstrip_);
tabstrip_->InitTabStripButtons();
frame_->TabStripCreated(tabstrip_); frame_->TabStripCreated(tabstrip_);
toolbar_ = new ToolbarView(browser_.get()); toolbar_ = new ToolbarView(browser_.get());
......
...@@ -117,6 +117,9 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -117,6 +117,9 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
InitClass(); InitClass();
ThemeProvider* tp = frame_->GetThemeProviderForFrame(); ThemeProvider* tp = frame_->GetThemeProviderForFrame();
SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
SkBitmap* background =
tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND);
minimize_button_->SetImage( minimize_button_->SetImage(
views::CustomButton::BS_NORMAL, views::CustomButton::BS_NORMAL,
...@@ -127,6 +130,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -127,6 +130,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
minimize_button_->SetImage( minimize_button_->SetImage(
views::CustomButton::BS_PUSHED, views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_MINIMIZE_P)); tp->GetBitmapNamed(IDR_MINIMIZE_P));
minimize_button_->SetBackground(color, background,
tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK));
minimize_button_->SetAccessibleName( minimize_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_MINIMIZE)); l10n_util::GetString(IDS_ACCNAME_MINIMIZE));
AddChildView(minimize_button_); AddChildView(minimize_button_);
...@@ -140,6 +145,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -140,6 +145,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
maximize_button_->SetImage( maximize_button_->SetImage(
views::CustomButton::BS_PUSHED, views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_MAXIMIZE_P)); tp->GetBitmapNamed(IDR_MAXIMIZE_P));
maximize_button_->SetBackground(color, background,
tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK));
maximize_button_->SetAccessibleName( maximize_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_MAXIMIZE)); l10n_util::GetString(IDS_ACCNAME_MAXIMIZE));
AddChildView(maximize_button_); AddChildView(maximize_button_);
...@@ -153,6 +160,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -153,6 +160,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
restore_button_->SetImage( restore_button_->SetImage(
views::CustomButton::BS_PUSHED, views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_RESTORE_P)); tp->GetBitmapNamed(IDR_RESTORE_P));
restore_button_->SetBackground(color, background,
tp->GetBitmapNamed(IDR_RESTORE_BUTTON_MASK));
restore_button_->SetAccessibleName( restore_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_RESTORE)); l10n_util::GetString(IDS_ACCNAME_RESTORE));
AddChildView(restore_button_); AddChildView(restore_button_);
...@@ -166,6 +175,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -166,6 +175,8 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
close_button_->SetImage( close_button_->SetImage(
views::CustomButton::BS_PUSHED, views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_CLOSE_P)); tp->GetBitmapNamed(IDR_CLOSE_P));
close_button_->SetBackground(color, background,
tp->GetBitmapNamed(IDR_CLOSE_BUTTON_MASK));
close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE)); close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
AddChildView(close_button_); AddChildView(close_button_);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#endif #endif
#include "base/gfx/size.h" #include "base/gfx/size.h"
#include "base/stl_util-inl.h" #include "base/stl_util-inl.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h" #include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "views/controls/image_view.h" #include "views/controls/image_view.h"
#include "views/painter.h" #include "views/painter.h"
#include "views/widget/default_theme_provider.h"
#include "views/window/non_client_view.h" #include "views/window/non_client_view.h"
#include "views/window/window.h" #include "views/window/window.h"
...@@ -595,6 +597,13 @@ void TabStrip::SetBackgroundOffset(gfx::Point offset) { ...@@ -595,6 +597,13 @@ void TabStrip::SetBackgroundOffset(gfx::Point offset) {
GetTabAt(i)->SetBackgroundOffset(offset); GetTabAt(i)->SetBackgroundOffset(offset);
} }
void TabStrip::InitTabStripButtons() {
newtab_button_ = new NewTabButton(this);
LoadNewTabButtonImage();
newtab_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_NEWTAB));
AddChildView(newtab_button_);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TabStrip, views::View overrides: // TabStrip, views::View overrides:
...@@ -768,6 +777,10 @@ views::View* TabStrip::GetViewForPoint(const gfx::Point& point) { ...@@ -768,6 +777,10 @@ views::View* TabStrip::GetViewForPoint(const gfx::Point& point) {
return this; return this;
} }
void TabStrip::ThemeChanged() {
LoadNewTabButtonImage();
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TabStrip, TabStripModelObserver implementation: // TabStrip, TabStripModelObserver implementation:
...@@ -1075,23 +1088,7 @@ void TabStrip::DidProcessEvent(GdkEvent* event) { ...@@ -1075,23 +1088,7 @@ void TabStrip::DidProcessEvent(GdkEvent* event) {
void TabStrip::Init() { void TabStrip::Init() {
model_->AddObserver(this); model_->AddObserver(this);
newtab_button_ = new NewTabButton(this); newtab_button_size_.SetSize(kNewTabButtonWidth, kNewTabButtonHeight);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
SkBitmap* bitmap;
bitmap = rb.GetBitmapNamed(IDR_NEWTAB_BUTTON);
newtab_button_->SetImage(views::CustomButton::BS_NORMAL, bitmap);
newtab_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_P));
newtab_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_H));
newtab_button_size_.SetSize(bitmap->width(), bitmap->height());
actual_newtab_button_size_ = newtab_button_size_;
newtab_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_NEWTAB));
AddChildView(newtab_button_);
if (drop_indicator_width == 0) { if (drop_indicator_width == 0) {
// Direction doesn't matter, both images are the same size. // Direction doesn't matter, both images are the same size.
SkBitmap* drop_image = GetDropArrowImage(true); SkBitmap* drop_image = GetDropArrowImage(true);
...@@ -1100,6 +1097,28 @@ void TabStrip::Init() { ...@@ -1100,6 +1097,28 @@ void TabStrip::Init() {
} }
} }
void TabStrip::LoadNewTabButtonImage() {
ThemeProvider* tp = GetThemeProvider();
// If we don't have a theme provider yet, it means we do not have a
// root view, and are therefore in a test.
if (tp == NULL)
tp = new views::DefaultThemeProvider();
SkBitmap* bitmap = tp->GetBitmapNamed(IDR_NEWTAB_BUTTON);
SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
SkBitmap* background = tp->GetBitmapNamed(
IDR_THEME_WINDOW_CONTROL_BACKGROUND);
newtab_button_->SetImage(views::CustomButton::BS_NORMAL, bitmap);
newtab_button_->SetImage(views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_P));
newtab_button_->SetImage(views::CustomButton::BS_HOT,
tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_H));
newtab_button_->SetBackground(color, background,
tp->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK));
}
Tab* TabStrip::GetTabAt(int index) const { Tab* TabStrip::GetTabAt(int index) const {
DCHECK(index >= 0 && index < GetTabCount()); DCHECK(index >= 0 && index < GetTabCount());
return tab_data_.at(index).tab; return tab_data_.at(index).tab;
......
...@@ -89,6 +89,9 @@ class TabStrip : public views::View, ...@@ -89,6 +89,9 @@ class TabStrip : public views::View,
// Set the background offset used by inactive tabs to match the frame image. // Set the background offset used by inactive tabs to match the frame image.
void SetBackgroundOffset(gfx::Point offset); void SetBackgroundOffset(gfx::Point offset);
// Create the new tab button.
void InitTabStripButtons();
// views::View overrides: // views::View overrides:
virtual void PaintChildren(gfx::Canvas* canvas); virtual void PaintChildren(gfx::Canvas* canvas);
virtual views::View* GetViewByID(int id) const; virtual views::View* GetViewByID(int id) const;
...@@ -104,6 +107,7 @@ class TabStrip : public views::View, ...@@ -104,6 +107,7 @@ class TabStrip : public views::View,
virtual bool GetAccessibleName(std::wstring* name); virtual bool GetAccessibleName(std::wstring* name);
virtual void SetAccessibleName(const std::wstring& name); virtual void SetAccessibleName(const std::wstring& name);
virtual views::View* GetViewForPoint(const gfx::Point& point); virtual views::View* GetViewForPoint(const gfx::Point& point);
virtual void ThemeChanged();
protected: protected:
// TabStripModelObserver implementation: // TabStripModelObserver implementation:
...@@ -166,6 +170,9 @@ class TabStrip : public views::View, ...@@ -166,6 +170,9 @@ class TabStrip : public views::View,
TabStrip(); TabStrip();
void Init(); void Init();
// Set the images for the new tab button.
void LoadNewTabButtonImage();
// Retrieves the Tab at the specified index. Take care in using this, you may // Retrieves the Tab at the specified index. Take care in using this, you may
// need to use GetTabAtAdjustForAnimation. // need to use GetTabAtAdjustForAnimation.
Tab* GetTabAt(int index) const; Tab* GetTabAt(int index) const;
...@@ -303,7 +310,6 @@ class TabStrip : public views::View, ...@@ -303,7 +310,6 @@ class TabStrip : public views::View,
// The "New Tab" button. // The "New Tab" button.
views::ImageButton* newtab_button_; views::ImageButton* newtab_button_;
gfx::Size newtab_button_size_; gfx::Size newtab_button_size_;
gfx::Size actual_newtab_button_size_;
// The current widths of various types of tabs. We save these so that, as // The current widths of various types of tabs. We save these so that, as
// users close tabs while we're holding them at the same size, we can lay out // users close tabs while we're holding them at the same size, we can lay out
...@@ -324,6 +330,13 @@ class TabStrip : public views::View, ...@@ -324,6 +330,13 @@ class TabStrip : public views::View,
// Storage of strings needed for accessibility. // Storage of strings needed for accessibility.
std::wstring accessible_name_; std::wstring accessible_name_;
// The size of the new tab button must be hardcoded because we need to be
// able to lay it out before we are able to get its image from the
// ThemeProvider. It also makes sense to do this, because the size of the
// new tab button should not need to be calculated dynamically.
static const int kNewTabButtonWidth = 28;
static const int kNewTabButtonHeight = 18;
// Used during a drop session of a url. Tracks the position of the drop as // Used during a drop session of a url. Tracks the position of the drop as
// well as a window used to highlight where the drop occurs. // well as a window used to highlight where the drop occurs.
struct DropInfo { struct DropInfo {
......
...@@ -17,6 +17,7 @@ class TestBrowserWindow : public BrowserWindow { ...@@ -17,6 +17,7 @@ class TestBrowserWindow : public BrowserWindow {
public: public:
explicit TestBrowserWindow(Browser* browser) explicit TestBrowserWindow(Browser* browser)
: tab_strip_(browser->tabstrip_model()) { : tab_strip_(browser->tabstrip_model()) {
tab_strip_.InitTabStripButtons();
} }
~TestBrowserWindow() {} ~TestBrowserWindow() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment