Commit e78f12a2 authored by pkasting@chromium.org's avatar pkasting@chromium.org

Toolbar layout changes for M6 theme.

BUG=50107
TEST=none
Review URL: http://codereview.chromium.org/3033036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54049 0039d316-1c4b-4281-b951-d872f2087c98
parent f59ce13e
...@@ -33,9 +33,17 @@ ...@@ -33,9 +33,17 @@
#include "views/window/non_client_view.h" #include "views/window/non_client_view.h"
#include "views/window/window.h" #include "views/window/window.h"
static const int kControlHorizOffset = 4; // The space between items is 4 px in general.
static const int kControlVertOffset = 6; const int ToolbarView::kStandardSpacing = 4;
static const int kControlIndent = 3; // The top of the toolbar has an edge we have to skip over in addition to the 4
// px of spacing.
const int ToolbarView::kVertSpacing = kStandardSpacing + 1;
// The edge graphics have some built-in spacing/shadowing, so we have to adjust
// our spacing to make it still appear to be 4 px.
static const int kEdgeSpacing = ToolbarView::kStandardSpacing - 1;
// The buttons to the left of the omnibox are close together.
static const int kButtonSpacing = 1;
static const int kStatusBubbleWidth = 480; static const int kStatusBubbleWidth = 480;
// The length of time to run the upgrade notification animation (the time it // The length of time to run the upgrade notification animation (the time it
...@@ -45,15 +53,6 @@ static const int kPulseDuration = 2000; ...@@ -45,15 +53,6 @@ static const int kPulseDuration = 2000;
// How long to wait between pulsating the upgrade notifier. // How long to wait between pulsating the upgrade notifier.
static const int kPulsateEveryMs = 8000; static const int kPulsateEveryMs = 8000;
// The offset in pixels of the upgrade dot on the app menu.
static const int kUpgradeDotOffset = 11;
// Separation between the location bar and the menus.
static const int kMenuButtonOffset = 3;
// Padding to the right of the location bar
static const int kPaddingRight = 2;
static const int kPopupTopSpacingNonGlass = 3; static const int kPopupTopSpacingNonGlass = 3;
static const int kPopupBottomSpacingNonGlass = 2; static const int kPopupBottomSpacingNonGlass = 2;
static const int kPopupBottomSpacingGlass = 1; static const int kPopupBottomSpacingGlass = 1;
...@@ -155,6 +154,7 @@ void ToolbarView::Init(Profile* profile) { ...@@ -155,6 +154,7 @@ void ToolbarView::Init(Profile* profile) {
browser_actions_ = new BrowserActionsContainer(browser_, this); browser_actions_ = new BrowserActionsContainer(browser_, this);
app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
app_menu_->set_border(NULL);
app_menu_->EnableCanvasFlippingForRTLUI(true); app_menu_->EnableCanvasFlippingForRTLUI(true);
app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP));
app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP,
...@@ -281,7 +281,9 @@ void ToolbarView::OnInputInProgress(bool in_progress) { ...@@ -281,7 +281,9 @@ void ToolbarView::OnInputInProgress(bool in_progress) {
// ToolbarView, AnimationDelegate implementation: // ToolbarView, AnimationDelegate implementation:
void ToolbarView::AnimationProgressed(const Animation* animation) { void ToolbarView::AnimationProgressed(const Animation* animation) {
app_menu_->SetIcon(GetAppMenuIcon()); app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL));
app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT));
app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED));
SchedulePaint(); SchedulePaint();
} }
...@@ -386,14 +388,14 @@ void ToolbarView::ExecuteCommand(int command_id) { ...@@ -386,14 +388,14 @@ void ToolbarView::ExecuteCommand(int command_id) {
gfx::Size ToolbarView::GetPreferredSize() { gfx::Size ToolbarView::GetPreferredSize() {
if (IsDisplayModeNormal()) { if (IsDisplayModeNormal()) {
int min_width = kControlIndent + back_->GetPreferredSize().width() + int min_width = kEdgeSpacing +
forward_->GetPreferredSize().width() + kControlHorizOffset + back_->GetPreferredSize().width() + kButtonSpacing +
reload_->GetPreferredSize().width() + kControlHorizOffset + forward_->GetPreferredSize().width() + kButtonSpacing +
reload_->GetPreferredSize().width() + kStandardSpacing +
(show_home_button_.GetValue() ? (show_home_button_.GetValue() ?
(home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + (home_->GetPreferredSize().width() + kButtonSpacing) : 0) +
browser_actions_->GetPreferredSize().width() + browser_actions_->GetPreferredSize().width() +
kMenuButtonOffset + app_menu_->GetPreferredSize().width() + kEdgeSpacing;
app_menu_->GetPreferredSize().width() + kPaddingRight;
static SkBitmap normal_background; static SkBitmap normal_background;
if (normal_background.isNull()) { if (normal_background.isNull()) {
...@@ -424,7 +426,7 @@ void ToolbarView::Layout() { ...@@ -424,7 +426,7 @@ void ToolbarView::Layout() {
return; return;
} }
int child_y = std::min(kControlVertOffset, height()); int child_y = std::min(kVertSpacing, height());
// We assume all child elements are the same height. // We assume all child elements are the same height.
int child_height = int child_height =
std::min(back_->GetPreferredSize().height(), height() - child_y); std::min(back_->GetPreferredSize().height(), height() - child_y);
...@@ -438,20 +440,20 @@ void ToolbarView::Layout() { ...@@ -438,20 +440,20 @@ void ToolbarView::Layout() {
// http://crbug.com/5540 // http://crbug.com/5540
int back_width = back_->GetPreferredSize().width(); int back_width = back_->GetPreferredSize().width();
if (browser_->window() && browser_->window()->IsMaximized()) if (browser_->window() && browser_->window()->IsMaximized())
back_->SetBounds(0, child_y, back_width + kControlIndent, child_height); back_->SetBounds(0, child_y, back_width + kEdgeSpacing, child_height);
else else
back_->SetBounds(kControlIndent, child_y, back_width, child_height); back_->SetBounds(kEdgeSpacing, child_y, back_width, child_height);
forward_->SetBounds(back_->x() + back_->width(), child_y, forward_->SetBounds(back_->x() + back_->width() + kButtonSpacing,
forward_->GetPreferredSize().width(), child_height); child_y, forward_->GetPreferredSize().width(), child_height);
reload_->SetBounds(forward_->x() + forward_->width() + kControlHorizOffset, reload_->SetBounds(forward_->x() + forward_->width() + kButtonSpacing,
child_y, reload_->GetPreferredSize().width(), child_height); child_y, reload_->GetPreferredSize().width(), child_height);
if (show_home_button_.GetValue()) { if (show_home_button_.GetValue()) {
home_->SetVisible(true); home_->SetVisible(true);
home_->SetBounds(reload_->x() + reload_->width() + kControlHorizOffset, home_->SetBounds(reload_->x() + reload_->width() + kButtonSpacing, child_y,
child_y, home_->GetPreferredSize().width(), child_height); home_->GetPreferredSize().width(), child_height);
} else { } else {
home_->SetVisible(false); home_->SetVisible(false);
home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height);
...@@ -459,16 +461,15 @@ void ToolbarView::Layout() { ...@@ -459,16 +461,15 @@ void ToolbarView::Layout() {
int browser_actions_width = browser_actions_->GetPreferredSize().width(); int browser_actions_width = browser_actions_->GetPreferredSize().width();
int app_menu_width = app_menu_->GetPreferredSize().width(); int app_menu_width = app_menu_->GetPreferredSize().width();
int location_x = home_->x() + home_->width() + kControlHorizOffset; int location_x = home_->x() + home_->width() + kStandardSpacing;
int available_width = width() - kPaddingRight - app_menu_width - int available_width = width() - kEdgeSpacing - app_menu_width -
browser_actions_width - kMenuButtonOffset - location_x; browser_actions_width - location_x;
location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0),
child_height); child_height);
int next_menu_x =
location_bar_->x() + location_bar_->width() + kMenuButtonOffset;
browser_actions_->SetBounds(next_menu_x, 0, browser_actions_width, height()); browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0,
browser_actions_width, height());
// The browser actions need to do a layout explicitly, because when an // The browser actions need to do a layout explicitly, because when an
// extension is loaded/unloaded/changed, BrowserActionContainer removes and // extension is loaded/unloaded/changed, BrowserActionContainer removes and
// re-adds everything, regardless of whether it has a page action. For a // re-adds everything, regardless of whether it has a page action. For a
...@@ -477,9 +478,9 @@ void ToolbarView::Layout() { ...@@ -477,9 +478,9 @@ void ToolbarView::Layout() {
// TODO(sidchat): Rework the above behavior so that explicit layout is not // TODO(sidchat): Rework the above behavior so that explicit layout is not
// required. // required.
browser_actions_->Layout(); browser_actions_->Layout();
next_menu_x += browser_actions_width;
app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); app_menu_->SetBounds(browser_actions_->x() + browser_actions_width, child_y,
app_menu_width, child_height);
} }
void ToolbarView::Paint(gfx::Canvas* canvas) { void ToolbarView::Paint(gfx::Canvas* canvas) {
...@@ -567,7 +568,9 @@ void ToolbarView::LoadImages() { ...@@ -567,7 +568,9 @@ void ToolbarView::LoadImages() {
home_->SetImage(views::CustomButton::BS_PUSHED, home_->SetImage(views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_HOME_P)); tp->GetBitmapNamed(IDR_HOME_P));
app_menu_->SetIcon(GetAppMenuIcon()); app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL));
app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT));
app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED));
} }
void ToolbarView::ShowUpgradeReminder() { void ToolbarView::ShowUpgradeReminder() {
...@@ -586,10 +589,17 @@ void ToolbarView::PulsateUpgradeNotifier() { ...@@ -586,10 +589,17 @@ void ToolbarView::PulsateUpgradeNotifier() {
update_reminder_animation_->Show(); update_reminder_animation_->Show();
} }
SkBitmap ToolbarView::GetAppMenuIcon() { SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) {
ThemeProvider* tp = GetThemeProvider(); ThemeProvider* tp = GetThemeProvider();
SkBitmap icon = *tp->GetBitmapNamed(IDR_TOOLS); int id = 0;
switch (state) {
case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break;
case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break;
case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break;
default: NOTREACHED(); break;
}
SkBitmap icon = *tp->GetBitmapNamed(id);
if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) if (!Singleton<UpgradeDetector>::get()->notify_upgrade())
return icon; return icon;
...@@ -625,8 +635,9 @@ SkBitmap ToolbarView::GetAppMenuIcon() { ...@@ -625,8 +635,9 @@ SkBitmap ToolbarView::GetAppMenuIcon() {
value); value);
} }
canvas->DrawBitmapInt(badge, kUpgradeDotOffset, static const int kBadgeLeftSpacing = 8;
icon.height() - badge.height()); static const int kBadgeTopSpacing = 18;
canvas->DrawBitmapInt(badge, kBadgeLeftSpacing, kBadgeTopSpacing);
return canvas->ExtractBitmap(); return canvas->ExtractBitmap();
} }
...@@ -117,6 +117,13 @@ class ToolbarView : public AccessibleToolbarView, ...@@ -117,6 +117,13 @@ class ToolbarView : public AccessibleToolbarView,
virtual void Paint(gfx::Canvas* canvas); virtual void Paint(gfx::Canvas* canvas);
virtual void OnThemeChanged(); virtual void OnThemeChanged();
// The apparent horizontal space between most items, and the vertical padding
// above and below them.
static const int kStandardSpacing;
// The top of the toolbar has an edge we have to skip over in addition to the
// standard spacing.
static const int kVertSpacing;
protected: protected:
// Overridden from AccessibleToolbarView // Overridden from AccessibleToolbarView
...@@ -149,7 +156,7 @@ class ToolbarView : public AccessibleToolbarView, ...@@ -149,7 +156,7 @@ class ToolbarView : public AccessibleToolbarView,
// Gets a canvas with the icon for the app menu. It will possibly contain // Gets a canvas with the icon for the app menu. It will possibly contain
// an overlaid badge if an update is recommended. // an overlaid badge if an update is recommended.
SkBitmap GetAppMenuIcon(); SkBitmap GetAppMenuIcon(views::CustomButton::ButtonState state);
scoped_ptr<BackForwardMenuModel> back_menu_model_; scoped_ptr<BackForwardMenuModel> back_menu_model_;
scoped_ptr<BackForwardMenuModel> forward_menu_model_; scoped_ptr<BackForwardMenuModel> forward_menu_model_;
......
...@@ -559,9 +559,7 @@ void WrenchMenu::Init(menus::MenuModel* model) { ...@@ -559,9 +559,7 @@ void WrenchMenu::Init(menus::MenuModel* model) {
void WrenchMenu::RunMenu(views::MenuButton* host) { void WrenchMenu::RunMenu(views::MenuButton* host) {
gfx::Point screen_loc; gfx::Point screen_loc;
views::View::ConvertPointToScreen(host, &screen_loc); views::View::ConvertPointToScreen(host, &screen_loc);
// Subtract 1 from the height to make the popup flush with the button border. gfx::Rect bounds(screen_loc, host->size());
gfx::Rect bounds(screen_loc.x(), screen_loc.y(), host->width(),
host->height() - 1);
root_->RunMenuAt(host->GetWindow()->GetNativeWindow(), host, bounds, root_->RunMenuAt(host->GetWindow()->GetNativeWindow(), host, bounds,
base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT, base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT,
true); true);
......
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