#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/bookmark_stats.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/wrench_menu_model.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h"
+#include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h"
#include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h"
+#include "chrome/browser/ui/zoom/zoom_controller.h"
+#include "chrome/browser/ui/zoom/zoom_event_manager.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/bookmarks/browser/bookmark_model.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
+#include "extensions/common/feature_switch.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/widget/widget.h"
-#if defined(USE_AURA)
-#include "ui/native_theme/native_theme_aura.h"
-#endif
-
using base::UserMetricsAction;
using content::HostZoomMap;
using content::WebContents;
namespace {
-// Horizontal padding on the edges of the buttons.
-const int kHorizontalPadding = 6;
-// Horizontal padding for a touch enabled menu.
-const int kHorizontalTouchPadding = 15;
-
-// Menu items which have embedded buttons should have this height in pixel.
-const int kMenuItemContainingButtonsHeight = 43;
+// Horizontal padding on the edges of the in-menu buttons.
+const int kHorizontalPadding = 15;
+
+#if defined(OS_CHROMEOS)
+// Extra horizontal space to reserve for the fullscreen button.
+const int kFullscreenPadding = 74;
+// Padding to left and right of the XX% label.
+const int kZoomLabelHorizontalPadding = kHorizontalPadding;
+#else
+const int kFullscreenPadding = 38;
+const int kZoomLabelHorizontalPadding = 2;
+#endif
// Returns true if |command_id| identifies a bookmark menu item.
bool IsBookmarkCommand(int command_id) {
: ImageButton(listener) { }
// Overridden from ImageButton.
- virtual gfx::Size GetPreferredSize() OVERRIDE {
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
gfx::Size pref = ImageButton::GetPreferredSize();
if (border()) {
gfx::Insets insets = border()->GetInsets();
DISALLOW_COPY_AND_ASSIGN(FullscreenButton);
};
-// Border for buttons contained in the menu. This is only used for getting the
-// insets, the actual painting is done in MenuButtonBackground.
-class MenuButtonBorder : public views::Border {
- public:
- MenuButtonBorder(const MenuConfig& config, bool use_new_menu)
- : horizontal_padding_(use_new_menu ?
- kHorizontalTouchPadding : kHorizontalPadding),
- insets_(config.item_top_margin, horizontal_padding_,
- config.item_bottom_margin, horizontal_padding_) {
- }
-
- // Overridden from views::Border.
- virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {
- // Painting of border is done in MenuButtonBackground.
- }
-
- virtual gfx::Insets GetInsets() const OVERRIDE {
- return insets_;
- }
-
- virtual gfx::Size GetMinimumSize() const OVERRIDE {
- // This size is sufficient for MenuButtonBackground::Paint() to draw any of
- // the button types.
- return gfx::Size(4, 4);
- }
-
- private:
- // The horizontal padding dependent on the layout.
- const int horizontal_padding_;
-
- const gfx::Insets insets_;
-
- DISALLOW_COPY_AND_ASSIGN(MenuButtonBorder);
-};
-
// Combination border/background for the buttons contained in the menu. The
-// painting of the border/background is done here as TextButton does not always
+// painting of the border/background is done here as LabelButton does not always
// paint the border.
-class MenuButtonBackground : public views::Background {
+class InMenuButtonBackground : public views::Background {
public:
enum ButtonType {
LEFT_BUTTON,
SINGLE_BUTTON,
};
- MenuButtonBackground(ButtonType type, bool use_new_menu)
- : type_(type),
- use_new_menu_(use_new_menu),
- left_button_(NULL),
- right_button_(NULL) {}
+ explicit InMenuButtonBackground(ButtonType type)
+ : type_(type), left_button_(NULL), right_button_(NULL) {}
// Used when the type is CENTER_BUTTON to determine if the left/right edge
// needs to be rendered selected.
- void SetOtherButtons(CustomButton* left_button, CustomButton* right_button) {
+ void SetOtherButtons(const CustomButton* left_button,
+ const CustomButton* right_button) {
if (base::i18n::IsRTL()) {
left_button_ = right_button;
right_button_ = left_button;
CustomButton* button = CustomButton::AsCustomButton(view);
views::Button::ButtonState state =
button ? button->state() : views::Button::STATE_NORMAL;
- int w = view->width();
int h = view->height();
-#if defined(USE_AURA)
+
// Normal buttons get a border drawn on the right side and the rest gets
// filled in. The left button however does not get a line to combine
// buttons.
- int border = 0;
if (type_ != RIGHT_BUTTON) {
- border = 1;
- canvas->FillRect(gfx::Rect(0, 0, border, h),
+ canvas->FillRect(gfx::Rect(0, 0, 1, h),
BorderColor(view, views::Button::STATE_NORMAL));
}
- if (use_new_menu_) {
- gfx::Rect bounds(view->GetLocalBounds());
- bounds.set_x(view->GetMirroredXForRect(bounds));
- DrawBackground(canvas, view, bounds, state);
- return;
- }
-#endif
- const SkColor border_color = BorderColor(view, state);
- switch (TypeAdjustedForRTL()) {
- // TODO(pkasting): Why don't all the following use SkPaths with rounded
- // corners?
- case LEFT_BUTTON:
- DrawBackground(canvas, view, gfx::Rect(1, 1, w, h - 2), state);
- canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color);
- canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color);
- canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color);
- break;
-
- case CENTER_BUTTON: {
- DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state);
- SkColor left_color = state != views::Button::STATE_NORMAL ?
- border_color : BorderColor(view, left_button_->state());
- canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color);
- canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color);
- canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1),
- border_color);
- SkColor right_color = state != views::Button::STATE_NORMAL ?
- border_color : BorderColor(view, right_button_->state());
- canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color);
- break;
- }
- case RIGHT_BUTTON:
- DrawBackground(canvas, view, gfx::Rect(0, 1, w - 1, h - 2), state);
- canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color);
- canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color);
- canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color);
- break;
-
- case SINGLE_BUTTON:
- DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state);
- canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color);
- canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color);
- canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color);
- canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color);
- canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color);
- canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color);
- break;
-
- default:
- NOTREACHED();
- break;
- }
+ gfx::Rect bounds(view->GetLocalBounds());
+ bounds.set_x(view->GetMirroredXForRect(bounds));
+ DrawBackground(canvas, view, bounds, state);
}
private:
ui::NativeTheme::kHovered,
bounds,
ui::NativeTheme::ExtraParams());
- return;
}
- if (use_new_menu_)
- return;
- canvas->FillRect(bounds, BackgroundColor(view, state));
}
ButtonType TypeAdjustedForRTL() const {
}
const ButtonType type_;
- const bool use_new_menu_;
// See description above setter for details.
- CustomButton* left_button_;
- CustomButton* right_button_;
+ const CustomButton* left_button_;
+ const CustomButton* right_button_;
- DISALLOW_COPY_AND_ASSIGN(MenuButtonBackground);
+ DISALLOW_COPY_AND_ASSIGN(InMenuButtonBackground);
};
base::string16 GetAccessibleNameForWrenchMenuItem(
accessible_name, accelerator_text);
}
+// A button that lives inside a menu item.
+class InMenuButton : public LabelButton {
+ public:
+ InMenuButton(views::ButtonListener* listener, const base::string16& text)
+ : LabelButton(listener, text), in_menu_background_(NULL) {}
+ virtual ~InMenuButton() {}
+
+ void Init(InMenuButtonBackground::ButtonType type) {
+ SetFocusable(true);
+ set_request_focus_on_press(false);
+ SetHorizontalAlignment(gfx::ALIGN_CENTER);
+
+ in_menu_background_ = new InMenuButtonBackground(type);
+ set_background(in_menu_background_);
+
+ OnNativeThemeChanged(NULL);
+ }
+
+ void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) {
+ in_menu_background_->SetOtherButtons(left, right);
+ }
+
+ // views::LabelButton
+ virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
+ const MenuConfig& menu_config = MenuConfig::instance(theme);
+ SetBorder(views::Border::CreateEmptyBorder(
+ 0, kHorizontalPadding, 0, kHorizontalPadding));
+ SetFontList(menu_config.font_list);
+
+ if (theme) {
+ SetTextColor(
+ views::Button::STATE_DISABLED,
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor));
+ SetTextColor(
+ views::Button::STATE_HOVERED,
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
+ SetTextColor(
+ views::Button::STATE_PRESSED,
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
+ SetTextColor(
+ views::Button::STATE_NORMAL,
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
+ }
+ }
+
+ private:
+ InMenuButtonBackground* in_menu_background_;
+
+ DISALLOW_COPY_AND_ASSIGN(InMenuButton);
+};
+
// WrenchMenuView is a view that can contain label buttons.
class WrenchMenuView : public views::View,
public views::ButtonListener,
// Overridden from views::View.
virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE {
// Normally when the mouse enters/exits a button the buttons invokes
- // SchedulePaint. As part of the button border (MenuButtonBackground) is
+ // SchedulePaint. As part of the button border (InMenuButtonBackground) is
// rendered by the button to the left/right of it SchedulePaint on the the
// button may not be enough, so this forces a paint all.
View::SchedulePaintInRect(gfx::Rect(size()));
}
- LabelButton* CreateAndConfigureButton(int string_id,
- MenuButtonBackground::ButtonType type,
- int index,
- MenuButtonBackground** background) {
- return CreateButtonWithAccName(
- string_id, type, index, background, string_id);
+ InMenuButton* CreateAndConfigureButton(
+ int string_id,
+ InMenuButtonBackground::ButtonType type,
+ int index) {
+ return CreateButtonWithAccName(string_id, type, index, string_id);
}
- LabelButton* CreateButtonWithAccName(int string_id,
- MenuButtonBackground::ButtonType type,
- int index,
- MenuButtonBackground** background,
- int acc_string_id) {
+ InMenuButton* CreateButtonWithAccName(int string_id,
+ InMenuButtonBackground::ButtonType type,
+ int index,
+ int acc_string_id) {
// Should only be invoked during construction when |menu_| is valid.
DCHECK(menu_);
- LabelButton* button = new LabelButton(this, gfx::RemoveAcceleratorChar(
- l10n_util::GetStringUTF16(string_id), '&', NULL, NULL));
+ InMenuButton* button = new InMenuButton(
+ this,
+ gfx::RemoveAcceleratorChar(
+ l10n_util::GetStringUTF16(string_id), '&', NULL, NULL));
+ button->Init(type);
button->SetAccessibleName(
GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id));
- button->SetFocusable(true);
- button->set_request_focus_on_press(false);
button->set_tag(index);
button->SetEnabled(menu_model_->IsEnabledAt(index));
- MenuButtonBackground* bg =
- new MenuButtonBackground(type, menu_->use_new_menu());
- button->set_background(bg);
- const MenuConfig& menu_config = menu_->GetMenuConfig();
- button->SetTextColor(views::Button::STATE_NORMAL, menu_config.text_color);
- if (background)
- *background = bg;
- button->SetBorder(scoped_ptr<views::Border>(
- new MenuButtonBorder(menu_config, menu_->use_new_menu())));
- button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
- button->SetFontList(menu_config.font_list);
- ui::NativeTheme* native_theme = button->GetNativeTheme();
- button->SetTextColor(
- views::Button::STATE_DISABLED,
- native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor));
- button->SetTextColor(
- views::Button::STATE_HOVERED,
- native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
- button->SetTextColor(
- views::Button::STATE_PRESSED,
- native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
- button->SetTextColor(
- views::Button::STATE_NORMAL,
- native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
+
AddChildView(button);
// all buttons on menu should must be a custom button in order for
// the keyboard nativigation work.
DISALLOW_COPY_AND_ASSIGN(WrenchMenuView);
};
-class ButtonContainerMenuItemView : public MenuItemView {
- public:
- // Constructor for use with button containing menu items which have a
- // different height then normal items.
- ButtonContainerMenuItemView(MenuItemView* parent, int command_id, int height)
- : MenuItemView(parent, command_id, MenuItemView::NORMAL),
- height_(height) {
- };
-
- // Overridden from MenuItemView.
- virtual gfx::Size GetChildPreferredSize() OVERRIDE {
- gfx::Size size = MenuItemView::GetChildPreferredSize();
- // When there is a height override given, we need to deduct our spacing
- // above and below to get to the correct height to return here for the
- // child item.
- int height = height_ - GetTopMargin() - GetBottomMargin();
- if (height > size.height())
- size.set_height(height);
- return size;
- }
-
- private:
- int height_;
-
- DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView);
-};
-
// Generate the button image for hover state.
class HoveredImageSource : public gfx::ImageSkiaSource {
public:
const gfx::ImageSkiaRep& rep = image_.GetRepresentation(scale);
SkBitmap bitmap = rep.sk_bitmap();
SkBitmap white;
- white.setConfig(SkBitmap::kARGB_8888_Config,
- bitmap.width(), bitmap.height(), 0);
- white.allocPixels();
+ white.allocN32Pixels(bitmap.width(), bitmap.height());
white.eraseARGB(0, 0, 0, 0);
bitmap.lockPixels();
for (int y = 0; y < bitmap.height(); ++y) {
public:
CutCopyPasteView(WrenchMenu* menu,
MenuModel* menu_model,
- const ui::NativeTheme* native_theme,
int cut_index,
int copy_index,
int paste_index)
: WrenchMenuView(menu, menu_model) {
- LabelButton* cut = CreateAndConfigureButton(
- IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL);
- MenuButtonBackground* copy_background = NULL;
- CreateAndConfigureButton(
- IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index,
- ©_background);
- LabelButton* paste = CreateAndConfigureButton(
- IDS_PASTE,
- menu->use_new_menu() && menu->supports_new_separators_ ?
- MenuButtonBackground::CENTER_BUTTON :
- MenuButtonBackground::RIGHT_BUTTON,
- paste_index,
- NULL);
- copy_background->SetOtherButtons(cut, paste);
+ InMenuButton* cut = CreateAndConfigureButton(
+ IDS_CUT, InMenuButtonBackground::LEFT_BUTTON, cut_index);
+ InMenuButton* copy = CreateAndConfigureButton(
+ IDS_COPY, InMenuButtonBackground::CENTER_BUTTON, copy_index);
+ InMenuButton* paste = CreateAndConfigureButton(
+ IDS_PASTE, InMenuButtonBackground::CENTER_BUTTON, paste_index);
+ copy->SetOtherButtons(cut, paste);
}
// Overridden from View.
- virtual gfx::Size GetPreferredSize() OVERRIDE {
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
// Returned height doesn't matter as MenuItemView forces everything to the
// height of the menuitemview.
return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0);
private:
// Returns the max preferred width of all the children.
- int GetMaxChildViewPreferredWidth() {
+ int GetMaxChildViewPreferredWidth() const {
int width = 0;
for (int i = 0; i < child_count(); ++i)
width = std::max(width, child_at(i)->GetPreferredSize().width());
// ZoomView --------------------------------------------------------------------
-// Padding between the increment buttons and the reset button.
-static const int kZoomPadding = 6;
-static const int kTouchZoomPadding = 14;
// ZoomView contains the various zoom controls: two buttons to increase/decrease
// the zoom, a label showing the current zoom percent, and a button to go
public:
ZoomView(WrenchMenu* menu,
MenuModel* menu_model,
- const ui::NativeTheme* native_theme,
int decrement_index,
int increment_index,
int fullscreen_index)
decrement_button_(NULL),
fullscreen_button_(NULL),
zoom_label_width_(0) {
- zoom_subscription_ = HostZoomMap::GetForBrowserContext(
+ content_zoom_subscription_ = HostZoomMap::GetDefaultForBrowserContext(
+ menu->browser_->profile())->AddZoomLevelChangedCallback(
+ base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
+ base::Unretained(this)));
+
+ browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext(
menu->browser_->profile())->AddZoomLevelChangedCallback(
base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
base::Unretained(this)));
decrement_button_ = CreateButtonWithAccName(
- IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index,
- NULL, IDS_ACCNAME_ZOOM_MINUS2);
+ IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON,
+ decrement_index, IDS_ACCNAME_ZOOM_MINUS2);
zoom_label_ = new Label(
l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
zoom_label_->SetAutoColorReadabilityEnabled(false);
zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
- MenuButtonBackground* center_bg = new MenuButtonBackground(
- menu->use_new_menu() && menu->supports_new_separators_ ?
- MenuButtonBackground::RIGHT_BUTTON :
- MenuButtonBackground::CENTER_BUTTON,
- menu->use_new_menu());
+ InMenuButtonBackground* center_bg =
+ new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON);
zoom_label_->set_background(center_bg);
- const MenuConfig& menu_config(menu->GetMenuConfig());
- zoom_label_->SetBorder(scoped_ptr<views::Border>(
- new MenuButtonBorder(menu_config, menu->use_new_menu())));
- zoom_label_->SetFontList(menu_config.font_list);
AddChildView(zoom_label_);
zoom_label_width_ = MaxWidthForZoomLabel();
increment_button_ = CreateButtonWithAccName(
- IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index,
- NULL, IDS_ACCNAME_ZOOM_PLUS2);
+ IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON,
+ increment_index, IDS_ACCNAME_ZOOM_PLUS2);
center_bg->SetOtherButtons(decrement_button_, increment_button_);
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_FULLSCREEN_MENU_BUTTON);
fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image);
- SkColor fg_color = native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
- gfx::ImageSkia hovered_fullscreen_image(
- new HoveredImageSource(*full_screen_image, fg_color),
- full_screen_image->size());
- fullscreen_button_->SetImage(
- ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
- fullscreen_button_->SetImage(
- ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
-
- SkColor enabled_text_color = native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
- zoom_label_->SetEnabledColor(enabled_text_color);
- decrement_button_->SetTextColor(views::Button::STATE_NORMAL,
- enabled_text_color);
- increment_button_->SetTextColor(views::Button::STATE_NORMAL,
- enabled_text_color);
- SkColor disabled_text_color = native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor);
- decrement_button_->SetTextColor(views::Button::STATE_DISABLED,
- disabled_text_color);
- increment_button_->SetTextColor(views::Button::STATE_DISABLED,
- disabled_text_color);
+
fullscreen_button_->SetFocusable(true);
fullscreen_button_->set_request_focus_on_press(false);
fullscreen_button_->set_tag(fullscreen_index);
fullscreen_button_->SetImageAlignment(
ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
- int horizontal_padding =
- menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding;
- fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder(
- 0, horizontal_padding, 0, horizontal_padding));
fullscreen_button_->set_background(
- new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON,
- menu->use_new_menu()));
+ new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON));
fullscreen_button_->SetAccessibleName(
GetAccessibleNameForWrenchMenuItem(
menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
AddChildView(fullscreen_button_);
+ // Need to set a font list for the zoom label width calculations.
+ OnNativeThemeChanged(NULL);
UpdateZoomControls();
}
virtual ~ZoomView() {}
// Overridden from View.
- virtual gfx::Size GetPreferredSize() OVERRIDE {
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
// The increment/decrement button are forced to the same width.
int button_width = std::max(increment_button_->GetPreferredSize().width(),
decrement_button_->GetPreferredSize().width());
- int zoom_padding = menu()->use_new_menu() ?
- kTouchZoomPadding : kZoomPadding;
- int fullscreen_width = fullscreen_button_->GetPreferredSize().width() +
- zoom_padding;
+ int fullscreen_width =
+ fullscreen_button_->GetPreferredSize().width() + kFullscreenPadding;
// Returned height doesn't matter as MenuItemView forces everything to the
// height of the menuitemview. Note that we have overridden the height when
// constructing the menu.
bounds.set_width(button_width);
increment_button_->SetBoundsRect(bounds);
- x += bounds.width() + (menu()->use_new_menu() ? 0 : kZoomPadding);
+ x += bounds.width();
bounds.set_x(x);
bounds.set_width(fullscreen_button_->GetPreferredSize().width() +
- (menu()->use_new_menu() ? kTouchZoomPadding : 0));
+ kFullscreenPadding);
fullscreen_button_->SetBoundsRect(bounds);
}
+ virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
+ WrenchMenuView::OnNativeThemeChanged(theme);
+
+ const MenuConfig& menu_config = MenuConfig::instance(theme);
+ zoom_label_->SetBorder(views::Border::CreateEmptyBorder(
+ 0, kZoomLabelHorizontalPadding, 0, kZoomLabelHorizontalPadding));
+ zoom_label_->SetFontList(menu_config.font_list);
+ zoom_label_width_ = MaxWidthForZoomLabel();
+
+ if (theme) {
+ zoom_label_->SetEnabledColor(theme->GetSystemColor(
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
+ gfx::ImageSkia* full_screen_image =
+ ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_FULLSCREEN_MENU_BUTTON);
+ SkColor fg_color = theme->GetSystemColor(
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
+ gfx::ImageSkia hovered_fullscreen_image(
+ new HoveredImageSource(*full_screen_image, fg_color),
+ full_screen_image->size());
+ fullscreen_button_->SetImage(
+ ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
+ fullscreen_button_->SetImage(
+ ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
+ }
+ }
+
// Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
}
void UpdateZoomControls() {
- bool enable_increment = false;
- bool enable_decrement = false;
WebContents* selected_tab =
menu()->browser_->tab_strip_model()->GetActiveWebContents();
int zoom = 100;
if (selected_tab)
- zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement);
- increment_button_->SetEnabled(enable_increment);
- decrement_button_->SetEnabled(enable_decrement);
+ zoom = ZoomController::FromWebContents(selected_tab)->GetZoomPercent();
+ increment_button_->SetEnabled(zoom < selected_tab->GetMaximumZoomPercent());
+ decrement_button_->SetEnabled(zoom > selected_tab->GetMinimumZoomPercent());
zoom_label_->SetText(
l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom));
// Index of the fullscreen menu item in the model.
const int fullscreen_index_;
- scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
+ scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_;
+ scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_;
content::NotificationRegistrar registrar_;
// Button for incrementing the zoom.
return model_->GetLabelFontListAt(index);
}
- bool GetForegroundColorAt(int index,
- bool is_hovered,
- SkColor* override_color) const {
- // The items for which we get a font list, should be shown in black.
- if (GetLabelFontListAt(index)) {
- *override_color = SK_ColorBLACK;
- return true;
- }
- return false;
+ bool GetShouldUseDisabledEmphasizedForegroundColor(int index) const {
+ // The items for which we get a font list, should be shown in the bolded
+ // color.
+ return GetLabelFontListAt(index) ? true : false;
}
// ui::MenuModelDelegate implementation:
// Add all menu items from |model| to submenu.
for (int i = 0; i < model_->GetItemCount(); ++i) {
- wrench_menu_->AddMenuItem(menu_item_, i, model_, i, model_->GetTypeAt(i),
- 0);
+ wrench_menu_->AddMenuItem(menu_item_, i, model_, i, model_->GetTypeAt(i));
}
// In case recent tabs submenu was open when items were changing, force a
// WrenchMenu ------------------------------------------------------------------
-WrenchMenu::WrenchMenu(Browser* browser,
- bool use_new_menu,
- bool supports_new_separators)
+WrenchMenu::WrenchMenu(Browser* browser, int run_flags)
: root_(NULL),
browser_(browser),
selected_menu_model_(NULL),
selected_index_(0),
bookmark_menu_(NULL),
feedback_menu_item_(NULL),
- use_new_menu_(use_new_menu),
- supports_new_separators_(supports_new_separators) {
+ run_flags_(run_flags) {
registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
content::Source<Profile>(browser_->profile()));
}
DCHECK(command_id_to_entry_.find(i) == command_id_to_entry_.end());
#endif // defined(DEBUG)
- menu_runner_.reset(new views::MenuRunner(root_));
+ int32 types = views::MenuRunner::HAS_MNEMONICS;
+ if (for_drop()) {
+ // We add NESTED_DRAG since currently the only operation to open the wrench
+ // menu for is an extension action drag, which is controlled by the child
+ // BrowserActionsContainer view.
+ types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG;
+ }
+ menu_runner_.reset(new views::MenuRunner(root_, types));
}
void WrenchMenu::RunMenu(views::MenuButton* host) {
views::View::ConvertPointToScreen(host, &screen_loc);
gfx::Rect bounds(screen_loc, host->size());
content::RecordAction(UserMetricsAction("ShowAppMenu"));
- if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds,
- MenuItemView::TOPRIGHT, ui::MENU_SOURCE_NONE,
- views::MenuRunner::HAS_MNEMONICS) ==
+ if (menu_runner_->RunMenuAt(host->GetWidget(),
+ host,
+ bounds,
+ views::MENU_ANCHOR_TOPRIGHT,
+ ui::MENU_SOURCE_NONE) ==
views::MenuRunner::MENU_DELETED)
return;
if (bookmark_menu_delegate_.get()) {
selected_menu_model_->ActivatedAt(selected_index_);
}
-bool WrenchMenu::IsShowing() {
- return menu_runner_.get() && menu_runner_->IsRunning();
-}
-
-const ui::NativeTheme* WrenchMenu::GetNativeTheme() const {
- views::Widget* browser_widget = views::Widget::GetWidgetForNativeView(
- browser_->window()->GetNativeWindow());
- DCHECK(browser_widget);
- return browser_widget->GetNativeTheme();
+void WrenchMenu::CloseMenu() {
+ if (menu_runner_.get())
+ menu_runner_->Cancel();
}
-const views::MenuConfig& WrenchMenu::GetMenuConfig() const {
- return MenuConfig::instance(GetNativeTheme());
+bool WrenchMenu::IsShowing() {
+ return menu_runner_.get() && menu_runner_->IsRunning();
}
void WrenchMenu::AddObserver(WrenchMenuObserver* observer) {
return NULL;
}
-bool WrenchMenu::GetForegroundColor(int command_id,
- bool is_hovered,
- SkColor* override_color) const {
+bool WrenchMenu::GetShouldUseDisabledEmphasizedForegroundColor(
+ int command_id) const {
if (IsRecentTabsCommand(command_id)) {
- return recent_tabs_menu_model_delegate_->GetForegroundColorAt(
- ModelIndexFromCommandId(command_id), is_hovered, override_color);
+ return recent_tabs_menu_model_delegate_->
+ GetShouldUseDisabledEmphasizedForegroundColor(
+ ModelIndexFromCommandId(command_id));
}
return false;
}
if (command_id == 0)
return false; // The root item.
- // The items representing the cut menu (cut/copy/paste) and zoom menu
- // (increment/decrement/reset) are always enabled. The child views of these
- // items enabled state updates appropriately.
- if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS)
+ // The items representing the cut menu (cut/copy/paste), zoom menu
+ // (increment/decrement/reset) and extension toolbar view are always enabled.
+ // The child views of these items enabled state updates appropriately.
+ if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
+ command_id == IDC_EXTENSIONS_OVERFLOW_MENU)
return true;
const Entry& entry = command_id_to_entry_.find(command_id)->second;
return;
}
- if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) {
+ if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
+ command_id == IDC_EXTENSIONS_OVERFLOW_MENU) {
// These items are represented by child views. If ExecuteCommand is invoked
// it means the user clicked on the area around the buttons and we should
// not do anyting.
return entry.first->ActivatedAt(entry.second, mouse_event_flags);
}
-bool WrenchMenu::GetAccelerator(int command_id, ui::Accelerator* accelerator) {
+bool WrenchMenu::GetAccelerator(int command_id,
+ ui::Accelerator* accelerator) const {
if (IsBookmarkCommand(command_id))
return false;
- if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) {
+ if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
+ command_id == IDC_EXTENSIONS_OVERFLOW_MENU) {
// These have special child views; don't show the accelerator for them.
return false;
}
- CommandIDToEntry::iterator ix = command_id_to_entry_.find(command_id);
+ CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
const Entry& entry = ix->second;
ui::Accelerator menu_accelerator;
if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator))
}
}
+bool WrenchMenu::ShouldCloseOnDragComplete() {
+ return false;
+}
+
void WrenchMenu::BookmarkModelChanged() {
DCHECK(bookmark_menu_delegate_.get());
if (!bookmark_menu_delegate_->is_mutating_model())
case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
// A change in the global errors list can add or remove items from the
// menu. Close the menu to avoid have a stale menu on-screen.
- root_->Cancel();
+ if (root_)
+ root_->Cancel();
break;
default:
NOTREACHED();
void WrenchMenu::PopulateMenu(MenuItemView* parent,
MenuModel* model) {
for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
- // The button container menu items have a special height which we have to
- // use instead of the normal height.
- int height = 0;
- if (use_new_menu_ &&
- (model->GetCommandIdAt(i) == IDC_CUT ||
- model->GetCommandIdAt(i) == IDC_ZOOM_MINUS))
- height = kMenuItemContainingButtonsHeight;
-
// Add the menu item at the end.
int menu_index = parent->HasSubmenu() ?
parent->GetSubmenu()->child_count() : 0;
- MenuItemView* item = AddMenuItem(
- parent, menu_index, model, i, model->GetTypeAt(i), height);
+ MenuItemView* item =
+ AddMenuItem(parent, menu_index, model, i, model->GetTypeAt(i));
+
+ if (model->GetCommandIdAt(i) == IDC_CUT ||
+ model->GetCommandIdAt(i) == IDC_ZOOM_MINUS) {
+ const MenuConfig& config = item->GetMenuConfig();
+ int top_margin = config.item_top_margin + config.separator_height / 2;
+ int bottom_margin =
+ config.item_bottom_margin + config.separator_height / 2;
+
+ // Chromeos adds extra vertical space for the menu buttons.
+#if defined(OS_CHROMEOS)
+ top_margin += 4;
+ bottom_margin += 5;
+#endif
+
+ item->SetMargins(top_margin, bottom_margin);
+ }
if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
PopulateMenu(item, model->GetSubmenuModelAt(i));
- const ui::NativeTheme* native_theme = GetNativeTheme();
-
switch (model->GetCommandIdAt(i)) {
+ case IDC_EXTENSIONS_OVERFLOW_MENU: {
+ scoped_ptr<ExtensionToolbarMenuView> extension_toolbar(
+ new ExtensionToolbarMenuView(browser_, this));
+ if (extension_toolbar->ShouldShow())
+ item->AddChildView(extension_toolbar.release());
+ else
+ item->SetVisible(false);
+ break;
+ }
+
case IDC_CUT:
DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i));
DCHECK_LT(i + 2, max);
DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1));
DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2));
item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2));
- item->AddChildView(new CutCopyPasteView(this, model, native_theme,
+ item->AddChildView(new CutCopyPasteView(this, model,
i, i + 1, i + 2));
i += 2;
break;
DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1));
DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2));
item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2));
- item->AddChildView(new ZoomView(this, model, native_theme,
- i, i + 1, i + 2));
+ item->AddChildView(new ZoomView(this, model, i, i + 1, i + 2));
i += 2;
break;
int menu_index,
MenuModel* model,
int model_index,
- MenuModel::ItemType menu_type,
- int height) {
+ MenuModel::ItemType menu_type) {
int command_id = model->GetCommandIdAt(model_index);
DCHECK(command_id > -1 ||
(command_id == -1 &&
command_id_to_entry_[command_id].second = model_index;
}
- MenuItemView* menu_item = NULL;
- if (height > 0) {
- // For menu items with a special menu height we use our special class to be
- // able to modify the item height.
- menu_item = new ButtonContainerMenuItemView(parent, command_id, height);
- parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index);
- } else {
- // For all other cases we use the more generic way to add menu items.
- menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt(
- model, model_index, parent, menu_index, command_id);
- }
+ MenuItemView* menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt(
+ model, model_index, parent, menu_index, command_id);
if (menu_item) {
// Flush all buttons to the right side of the menu for the new menu type.
- menu_item->set_use_right_margin(!use_new_menu_);
+ menu_item->set_use_right_margin(false);
menu_item->SetVisible(model->IsVisibleAt(model_index));
if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) {