summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/menus/accelerator.h14
-rw-r--r--views/accelerator.h5
-rw-r--r--views/controls/button/text_button.cc52
-rw-r--r--views/controls/button/text_button.h24
-rw-r--r--views/controls/menu/menu_config.h8
-rw-r--r--views/controls/menu/menu_config_gtk.cc1
-rw-r--r--views/controls/menu/menu_config_win.cc6
-rw-r--r--views/controls/menu/menu_item_view_gtk.cc3
-rw-r--r--views/controls/menu/menu_item_view_win.cc3
9 files changed, 85 insertions, 31 deletions
diff --git a/app/menus/accelerator.h b/app/menus/accelerator.h
index 1d659a4..0cb6279 100644
--- a/app/menus/accelerator.h
+++ b/app/menus/accelerator.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,13 +14,19 @@ namespace menus {
class Accelerator {
public:
- Accelerator() : key_code_(base::VKEY_UNKNOWN), modifiers_(0) { }
- virtual ~Accelerator() { }
+ Accelerator() : key_code_(base::VKEY_UNKNOWN), modifiers_(0) {}
+
+ Accelerator(base::KeyboardCode keycode, int modifiers)
+ : key_code_(keycode),
+ modifiers_(modifiers) {}
+
Accelerator(const Accelerator& accelerator) {
key_code_ = accelerator.key_code_;
modifiers_ = accelerator.modifiers_;
}
+ virtual ~Accelerator() {}
+
Accelerator& operator=(const Accelerator& accelerator) {
if (this != &accelerator) {
key_code_ = accelerator.key_code_;
@@ -54,7 +60,7 @@ class Accelerator {
}
protected:
- // The window keycode (VK_...).
+ // The keycode (VK_...).
base::KeyboardCode key_code_;
// The state of the Shift/Ctrl/Alt keys (platform-dependent).
diff --git a/views/accelerator.h b/views/accelerator.h
index a54a431..9296e88 100644
--- a/views/accelerator.h
+++ b/views/accelerator.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,6 +22,9 @@ class Accelerator : public menus::Accelerator {
public:
Accelerator() : menus::Accelerator() {}
+ Accelerator(base::KeyboardCode keycode, int modifiers)
+ : menus::Accelerator(keycode, modifiers) {}
+
Accelerator(base::KeyboardCode keycode,
bool shift_pressed, bool ctrl_pressed, bool alt_pressed) {
key_code_ = keycode;
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc
index 9fcf477..98c69fe 100644
--- a/views/controls/button/text_button.cc
+++ b/views/controls/button/text_button.cc
@@ -34,6 +34,20 @@ const SkColor TextButton::kHoverColor = TextButton::kEnabledColor;
// How long the hover fade animation should last.
static const int kHoverAnimationDurationMs = 170;
+static int PrefixTypeToCanvasType(TextButton::PrefixType type) {
+ switch (type) {
+ case TextButton::PREFIX_HIDE:
+ return gfx::Canvas::HIDE_PREFIX;
+ case TextButton::PREFIX_SHOW:
+ return gfx::Canvas::SHOW_PREFIX;
+ case TextButton::PREFIX_NONE:
+ return 0;
+ default:
+ NOTREACHED();
+ return 0;
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
//
// TextButtonBorder - constructors, destructors, initialization
@@ -176,7 +190,8 @@ TextButton::TextButton(ButtonListener* listener, const std::wstring& text)
has_hover_icon_(false),
max_width_(0),
normal_has_border_(false),
- show_highlighted_(true) {
+ show_highlighted_(true),
+ prefix_type_(PREFIX_NONE) {
SetText(text);
set_border(new TextButtonBorder);
SetAnimationDuration(kHoverAnimationDurationMs);
@@ -187,11 +202,7 @@ TextButton::~TextButton() {
void TextButton::SetText(const std::wstring& text) {
text_ = text;
- // Update our new current and max text size
- text_size_.SetSize(font_.GetStringWidth(text_), font_.height());
- max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()),
- std::max(max_text_size_.height(),
- text_size_.height()));
+ UpdateTextSize();
}
void TextButton::SetIcon(const SkBitmap& icon) {
@@ -205,6 +216,7 @@ void TextButton::SetHoverIcon(const SkBitmap& icon) {
void TextButton::SetFont(const gfx::Font& font) {
font_ = font;
+ UpdateTextSize();
}
void TextButton::SetEnabledColor(SkColor color) {
@@ -318,6 +330,9 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
else
text_color = color_;
+ int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() |
+ PrefixTypeToCanvasType(prefix_type_);
+
if (for_drag) {
#if defined(OS_WIN)
// TODO(erg): Either port DrawStringWithHalo to linux or find an
@@ -327,7 +342,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
text_bounds.y(),
text_bounds.width(),
text_bounds.height(),
- gfx::Canvas::DefaultCanvasTextAlignment());
+ draw_string_flags);
#else
canvas->DrawStringInt(text_,
font_,
@@ -335,7 +350,8 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
text_bounds.x(),
text_bounds.y(),
text_bounds.width(),
- text_bounds.height());
+ text_bounds.height(),
+ draw_string_flags);
#endif
} else {
canvas->DrawStringInt(text_,
@@ -344,7 +360,8 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
text_bounds.x(),
text_bounds.y(),
text_bounds.width(),
- text_bounds.height());
+ text_bounds.height(),
+ draw_string_flags);
}
}
@@ -362,6 +379,17 @@ void TextButton::UpdateColor() {
color_ = IsEnabled() ? color_enabled_ : color_disabled_;
}
+void TextButton::UpdateTextSize() {
+ int width = 0, height = 0;
+ gfx::Canvas::SizeStringInt(
+ text_, font_, &width, &height,
+ gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_));
+ text_size_.SetSize(width, font_.height());
+ max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()),
+ std::max(max_text_size_.height(),
+ text_size_.height()));
+}
+
////////////////////////////////////////////////////////////////////////////////
// TextButton, View overrides:
@@ -396,12 +424,6 @@ void TextButton::SetEnabled(bool enabled) {
SchedulePaint();
}
-bool TextButton::OnMousePressed(const MouseEvent& e) {
- if (request_focus_on_press())
- RequestFocus();
- return true;
-}
-
void TextButton::Paint(gfx::Canvas* canvas) {
Paint(canvas, false);
}
diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h
index 4257f0a..5953a34 100644
--- a/views/controls/button/text_button.h
+++ b/views/controls/button/text_button.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -71,6 +71,19 @@ class TextButtonBorder : public Border {
////////////////////////////////////////////////////////////////////////////////
class TextButton : public CustomButton {
public:
+ // Enumeration of how the prefix ('&') character is processed. The default
+ // is |PREFIX_NONE|.
+ enum PrefixType {
+ // No special processing is done.
+ PREFIX_NONE,
+
+ // The character following the prefix character is not rendered specially.
+ PREFIX_HIDE,
+
+ // The character following the prefix character is underlined.
+ PREFIX_SHOW
+ };
+
TextButton(ButtonListener* listener, const std::wstring& text);
virtual ~TextButton();
@@ -88,6 +101,8 @@ class TextButton : public CustomButton {
void set_alignment(TextAlignment alignment) { alignment_ = alignment; }
+ void set_prefix_type(PrefixType type) { prefix_type_ = type; }
+
// Sets the icon.
void SetIcon(const SkBitmap& icon);
SkBitmap icon() const { return icon_; }
@@ -136,7 +151,6 @@ class TextButton : public CustomButton {
static const SkColor kHoverColor;
protected:
- virtual bool OnMousePressed(const MouseEvent& e);
virtual void Paint(gfx::Canvas* canvas);
// Called when enabled or disabled state changes, or the colors for those
@@ -144,6 +158,10 @@ class TextButton : public CustomButton {
virtual void UpdateColor();
private:
+ // Updates text_size_ and max_text_size_ from the current text/font. This is
+ // invoked when the font or text changes.
+ void UpdateTextSize();
+
// The text string that is displayed in the button.
std::wstring text_;
@@ -189,6 +207,8 @@ class TextButton : public CustomButton {
// Whether or not to show the highlighted (i.e. hot) state.
bool show_highlighted_;
+ PrefixType prefix_type_;
+
DISALLOW_COPY_AND_ASSIGN(TextButton);
};
diff --git a/views/controls/menu/menu_config.h b/views/controls/menu/menu_config.h
index cd41fea..9a9a60e 100644
--- a/views/controls/menu/menu_config.h
+++ b/views/controls/menu/menu_config.h
@@ -6,6 +6,7 @@
#define VIEWS_CONTROLS_MENU_MENU_CONFIG_H_
#include "gfx/font.h"
+#include "third_party/skia/include/core/SkColor.h"
namespace views {
@@ -13,7 +14,8 @@ namespace views {
// the MenuConfig for the current platform.
struct MenuConfig {
MenuConfig()
- : item_top_margin(3),
+ : text_color(SK_ColorBLACK),
+ item_top_margin(3),
item_bottom_margin(4),
item_no_icon_top_margin(1),
item_no_icon_bottom_margin(3),
@@ -44,8 +46,8 @@ struct MenuConfig {
// Font used by menus.
gfx::Font font;
- // Font used when the menu has children.
- gfx::Font font_with_controls;
+ // Normal text color.
+ SkColor text_color;
// Margins between the top of the item and the label.
int item_top_margin;
diff --git a/views/controls/menu/menu_config_gtk.cc b/views/controls/menu/menu_config_gtk.cc
index 30b59a1..971490b 100644
--- a/views/controls/menu/menu_config_gtk.cc
+++ b/views/controls/menu/menu_config_gtk.cc
@@ -15,7 +15,6 @@ MenuConfig* MenuConfig::Create() {
MenuConfig* config = new MenuConfig();
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
config->font = rb.GetFont(ResourceBundle::BaseFont);
- config->font_with_controls = config->font.DeriveFont(0, gfx::Font::BOLD);
config->arrow_width = rb.GetBitmapNamed(IDR_MENU_ARROW)->width();
// Add 4 to force some padding between check and label.
config->check_width = rb.GetBitmapNamed(IDR_MENU_CHECK)->width() + 4;
diff --git a/views/controls/menu/menu_config_win.cc b/views/controls/menu/menu_config_win.cc
index bff25fd..aee41e9 100644
--- a/views/controls/menu/menu_config_win.cc
+++ b/views/controls/menu/menu_config_win.cc
@@ -20,13 +20,17 @@ namespace views {
// static
MenuConfig* MenuConfig::Create() {
MenuConfig* config = new MenuConfig();
+
+ config->text_color = NativeTheme::instance()->GetThemeColorWithDefault(
+ NativeTheme::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR,
+ COLOR_MENUTEXT);
+
NONCLIENTMETRICS metrics;
win_util::GetNonClientMetrics(&metrics);
l10n_util::AdjustUIFont(&(metrics.lfMenuFont));
HFONT font = CreateFontIndirect(&metrics.lfMenuFont);
DLOG_ASSERT(font);
config->font = gfx::Font::CreateFont(font);
- config->font_with_controls = config->font.DeriveFont(0, gfx::Font::BOLD);
HDC dc = GetDC(NULL);
RECT bounds = { 0, 0, 200, 200 };
diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc
index 74255d1..fa0aeca 100644
--- a/views/controls/menu/menu_item_view_gtk.cc
+++ b/views/controls/menu/menu_item_view_gtk.cc
@@ -72,8 +72,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
SkColor fg_color =
IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor;
#endif
- const gfx::Font& font = GetChildViewCount() > 0 ?
- MenuConfig::instance().font_with_controls : MenuConfig::instance().font;
+ const gfx::Font& font = MenuConfig::instance().font;
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
gfx::Rect text_bounds(label_start_, top_margin +
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index 90e9755f..bfdac37 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -95,8 +95,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault(
NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR,
default_sys_color);
- const gfx::Font& font = GetChildViewCount() > 0 ?
- MenuConfig::instance().font_with_controls : MenuConfig::instance().font;
+ const gfx::Font& font = MenuConfig::instance().font;
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
gfx::Rect text_bounds(label_start_, top_margin, width, font.height());