summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_config_aura.cc30
-rw-r--r--views/controls/menu/menu_config_win.cc5
-rw-r--r--views/controls/menu/menu_image_util.cc (renamed from views/controls/menu/menu_image_util_linux.cc)2
-rw-r--r--views/controls/menu/menu_image_util.h (renamed from views/controls/menu/menu_image_util_linux.h)6
-rw-r--r--views/controls/menu/menu_item_view.cc25
-rw-r--r--views/controls/menu/menu_item_view_aura.cc107
-rw-r--r--views/controls/menu/menu_item_view_linux.cc27
-rw-r--r--views/controls/menu/menu_item_view_win.cc21
-rw-r--r--views/controls/menu/menu_scroll_view_container.cc42
-rw-r--r--views/controls/menu/menu_separator_aura.cc24
-rw-r--r--views/views.gyp13
11 files changed, 203 insertions, 99 deletions
diff --git a/views/controls/menu/menu_config_aura.cc b/views/controls/menu/menu_config_aura.cc
new file mode 100644
index 0000000..d0aca45
--- /dev/null
+++ b/views/controls/menu/menu_config_aura.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 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.
+
+#include "views/controls/menu/menu_config.h"
+
+#include "grit/ui_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace views {
+
+// static
+MenuConfig* MenuConfig::Create() {
+ MenuConfig* config = new MenuConfig();
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+#if defined(TOUCH_UI)
+ config->font = rb.GetFont(ResourceBundle::LargeFont);
+ config->show_accelerators = false;
+#else
+ config->font = rb.GetFont(ResourceBundle::BaseFont);
+#endif
+ 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;
+ config->check_height = rb.GetBitmapNamed(IDR_MENU_CHECK)->height();
+ return config;
+}
+
+} // namespace views
diff --git a/views/controls/menu/menu_config_win.cc b/views/controls/menu/menu_config_win.cc
index 762b7a5..869d131 100644
--- a/views/controls/menu/menu_config_win.cc
+++ b/views/controls/menu/menu_config_win.cc
@@ -23,14 +23,9 @@ namespace views {
MenuConfig* MenuConfig::Create() {
MenuConfig* config = new MenuConfig();
- // TODO(jamescook): Create menu_config_aura.cc instead.
-#if defined(USE_AURA)
- config->text_color = SK_ColorBLACK;
-#else
config->text_color = NativeThemeWin::instance()->GetThemeColorWithDefault(
NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR,
COLOR_MENUTEXT);
-#endif
NONCLIENTMETRICS metrics;
base::win::GetNonClientMetrics(&metrics);
diff --git a/views/controls/menu/menu_image_util_linux.cc b/views/controls/menu/menu_image_util.cc
index f3e3e3a..e9b4b81 100644
--- a/views/controls/menu/menu_image_util_linux.cc
+++ b/views/controls/menu/menu_image_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "views/controls/menu/menu_image_util_linux.h"
+#include "views/controls/menu/menu_image_util.h"
#include "base/i18n/rtl.h"
#include "grit/ui_resources.h"
diff --git a/views/controls/menu/menu_image_util_linux.h b/views/controls/menu/menu_image_util.h
index abf9bcb..bcf62fb 100644
--- a/views/controls/menu/menu_image_util_linux.h
+++ b/views/controls/menu/menu_image_util.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_H_
-#define VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_H_
+#ifndef VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_H_
+#define VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_H_
#pragma once
#include "third_party/skia/include/core/SkBitmap.h"
@@ -21,4 +21,4 @@ const SkBitmap* GetSubmenuArrowImage();
} // namespace views
-#endif // VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_H_
+#endif // VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_H_
diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc
index baa1ff1..67674fc 100644
--- a/views/controls/menu/menu_item_view.cc
+++ b/views/controls/menu/menu_item_view.cc
@@ -54,6 +54,10 @@ class EmptyMenuMenuItem : public MenuItemView {
// Padding between child views.
static const int kChildXPadding = 8;
+#if defined(TOUCH_UI)
+const int kMinItemHeightTouch = 40;
+#endif
+
// MenuItemView ---------------------------------------------------------------
// static
@@ -682,6 +686,27 @@ gfx::Size MenuItemView::GetChildPreferredSize() {
return gfx::Size(width, 0);
}
+gfx::Size MenuItemView::CalculatePreferredSize() {
+ gfx::Size child_size = GetChildPreferredSize();
+ if (child_count() == 1 && title_.empty()) {
+ return gfx::Size(
+ child_size.width(),
+ child_size.height() + GetBottomMargin() + GetTopMargin());
+ }
+
+ const gfx::Font& font = GetFont();
+#if defined(TOUCH_UI)
+ int height = std::max(font.GetHeight(), kMinItemHeightTouch);
+#else
+ int height = font.GetHeight();
+#endif
+ return gfx::Size(
+ font.GetStringWidth(title_) + label_start_ +
+ item_right_margin_ + child_size.width(),
+ std::max(height, child_size.height()) + GetBottomMargin() +
+ GetTopMargin());
+}
+
string16 MenuItemView::GetAcceleratorText() {
if (id() == kEmptyMenuItemViewID) {
// Don't query the delegate for menus that represent no children.
diff --git a/views/controls/menu/menu_item_view_aura.cc b/views/controls/menu/menu_item_view_aura.cc
new file mode 100644
index 0000000..3e8f1d9
--- /dev/null
+++ b/views/controls/menu/menu_item_view_aura.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2011 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.
+
+#include "views/controls/menu/menu_item_view.h"
+
+#include "base/utf_string_conversions.h"
+#include "grit/ui_resources.h"
+#include "third_party/skia/include/effects/SkGradientShader.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/favicon_size.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/menu/menu_config.h"
+#include "views/controls/menu/menu_image_util.h"
+#include "views/controls/menu/submenu_view.h"
+
+namespace views {
+
+// Background color when the menu item is selected.
+static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253);
+
+void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
+ const MenuConfig& config = MenuConfig::instance();
+ bool render_selection =
+ (mode == PB_NORMAL && IsSelected() &&
+ parent_menu_item_->GetSubmenu()->GetShowSelection(this) &&
+ !has_children());
+
+ int icon_x = config.item_left_margin;
+ int top_margin = GetTopMargin();
+ int bottom_margin = GetBottomMargin();
+ int icon_y = top_margin + (height() - config.item_top_margin -
+ bottom_margin - config.check_height) / 2;
+ int icon_height = config.check_height;
+ int available_height = height() - top_margin - bottom_margin;
+
+ // Render the background. As MenuScrollViewContainer draws the background, we
+ // only need the background when we want it to look different, as when we're
+ // selected.
+ if (render_selection)
+ canvas->GetSkCanvas()->drawColor(kSelectedBackgroundColor,
+ SkXfermode::kSrc_Mode);
+
+ // Render the check.
+ if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK);
+ // Don't use config.check_width here as it's padded to force more padding.
+ gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height);
+ AdjustBoundsForRTLUI(&check_bounds);
+ canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y());
+ } else if (type_ == RADIO) {
+ const SkBitmap* image =
+ GetRadioButtonImage(GetDelegate()->IsItemChecked(GetCommand()));
+ gfx::Rect radio_bounds(icon_x,
+ top_margin +
+ (height() - top_margin - bottom_margin -
+ image->height()) / 2,
+ image->width(),
+ image->height());
+ AdjustBoundsForRTLUI(&radio_bounds);
+ canvas->DrawBitmapInt(*image, radio_bounds.x(), radio_bounds.y());
+ }
+
+ // Render the foreground.
+ SkColor fg_color =
+ IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor;
+ const gfx::Font& font = GetFont();
+ 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 +
+ (available_height - font.GetHeight()) / 2, width,
+ font.GetHeight());
+ text_bounds.set_x(GetMirroredXForRect(text_bounds));
+ canvas->DrawStringInt(title(), font, fg_color,
+ text_bounds.x(), text_bounds.y(), text_bounds.width(),
+ text_bounds.height(),
+ GetRootMenuItem()->GetDrawStringFlags());
+
+ PaintAccelerator(canvas);
+
+ // Render the icon.
+ if (icon_.width() > 0) {
+ gfx::Rect icon_bounds(config.item_left_margin,
+ top_margin + (height() - top_margin -
+ bottom_margin - icon_.height()) / 2,
+ icon_.width(),
+ icon_.height());
+ icon_bounds.set_x(GetMirroredXForRect(icon_bounds));
+ canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y());
+ }
+
+ // Render the submenu indicator (arrow).
+ if (HasSubmenu()) {
+ gfx::Rect arrow_bounds(this->width() - item_right_margin_ +
+ config.label_to_arrow_padding,
+ top_margin + (available_height -
+ config.arrow_width) / 2,
+ config.arrow_width, height());
+ AdjustBoundsForRTLUI(&arrow_bounds);
+ canvas->DrawBitmapInt(*GetSubmenuArrowImage(),
+ arrow_bounds.x(), arrow_bounds.y());
+ }
+}
+
+} // namespace views
diff --git a/views/controls/menu/menu_item_view_linux.cc b/views/controls/menu/menu_item_view_linux.cc
index 30fddec..cca0a35 100644
--- a/views/controls/menu/menu_item_view_linux.cc
+++ b/views/controls/menu/menu_item_view_linux.cc
@@ -12,7 +12,7 @@
#include "ui/gfx/favicon_size.h"
#include "views/controls/button/text_button.h"
#include "views/controls/menu/menu_config.h"
-#include "views/controls/menu/menu_image_util_linux.h"
+#include "views/controls/menu/menu_image_util.h"
#include "views/controls/menu/submenu_view.h"
namespace views {
@@ -24,31 +24,6 @@ static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA);
static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253);
#endif
-#if defined(TOUCH_UI)
-const int kMinTouchHeight = 40;
-#endif
-
-gfx::Size MenuItemView::CalculatePreferredSize() {
- gfx::Size child_size = GetChildPreferredSize();
- if (child_count() == 1 && title_.size() == 0) {
- return gfx::Size(
- child_size.width(),
- child_size.height() + GetBottomMargin() + GetTopMargin());
- }
-
- const gfx::Font& font = GetFont();
-#if defined(TOUCH_UI)
- int height = std::max(font.GetHeight(), kMinTouchHeight);
-#else
- int height = font.GetHeight();
-#endif
- return gfx::Size(
- font.GetStringWidth(title_) + label_start_ +
- item_right_margin_ + child_size.width(),
- std::max(height, child_size.height()) + GetBottomMargin() +
- GetTopMargin());
-}
-
void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
const MenuConfig& config = MenuConfig::instance();
bool render_selection =
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index f3b38a9..59ee57f 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -17,22 +17,6 @@ using gfx::NativeTheme;
namespace views {
-gfx::Size MenuItemView::CalculatePreferredSize() {
- gfx::Size child_size = GetChildPreferredSize();
- if (child_count() == 1 && title_.empty()) {
- return gfx::Size(
- child_size.width(),
- child_size.height() + GetBottomMargin() + GetTopMargin());
- }
-
- const gfx::Font& font = GetFont();
- return gfx::Size(
- font.GetStringWidth(title_) + label_start_ + item_right_margin_ +
- child_size.width(),
- std::max(child_size.height(), font.GetHeight()) + GetBottomMargin() +
- GetTopMargin());
-}
-
void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
const MenuConfig& config = MenuConfig::instance();
bool render_selection =
@@ -95,14 +79,9 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
// Render the foreground.
// Menu color is specific to Vista, fallback to classic colors if can't
// get color.
-#if defined(USE_AURA)
- // TODO(jamescook): Create menu_item_view_aura.cc
- SkColor fg_color = SK_ColorBLACK;
-#else
SkColor fg_color = gfx::NativeThemeWin::instance()->GetThemeColorWithDefault(
gfx::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR,
default_sys_color);
-#endif
const gfx::Font& font = GetFont();
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc
index cb52b41..6080167 100644
--- a/views/controls/menu/menu_scroll_view_container.cc
+++ b/views/controls/menu/menu_scroll_view_container.cc
@@ -13,18 +13,14 @@
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/color_utils.h"
+#include "ui/gfx/native_theme.h"
#include "views/border.h"
-#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/controls/menu/menu_config.h"
#include "views/controls/menu/menu_controller.h"
#include "views/controls/menu/menu_item_view.h"
#include "views/controls/menu/submenu_view.h"
-#if defined(OS_WIN)
-#include "ui/gfx/native_theme.h"
-
using gfx::NativeTheme;
-#endif
// Height of the scroll arrow.
// This goes up to 4 with large fonts, but this is close enough for now.
@@ -81,7 +77,6 @@ class MenuScrollButton : public View {
virtual void OnPaint(gfx::Canvas* canvas) {
const MenuConfig& config = MenuConfig::instance();
-#if defined(OS_WIN)
// The background.
gfx::Rect item_bounds(0, 0, width(), height());
NativeTheme::ExtraParams extra;
@@ -89,6 +84,7 @@ class MenuScrollButton : public View {
NativeTheme::instance()->Paint(canvas->GetSkCanvas(),
NativeTheme::kMenuItemBackground,
NativeTheme::kNormal, item_bounds, extra);
+#if defined(OS_WIN)
SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT);
#else
SkColor arrow_color = SK_ColorBLACK;
@@ -184,43 +180,13 @@ void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) {
#if defined(OS_WIN)
HDC dc = canvas->BeginPlatformPaint();
+#endif
gfx::Rect bounds(0, 0, width(), height());
NativeTheme::ExtraParams extra;
NativeTheme::instance()->Paint(canvas->GetSkCanvas(),
NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra);
+#if defined(OS_WIN)
canvas->EndPlatformPaint();
-#elif defined(OS_CHROMEOS)
- static const SkColor kGradientColors[2] = {
- SK_ColorWHITE,
- SkColorSetRGB(0xF0, 0xF0, 0xF0)
- };
-
- static const SkScalar kGradientPoints[2] = {
- SkIntToScalar(0),
- SkIntToScalar(1)
- };
-
- SkPoint points[2];
- points[0].set(SkIntToScalar(0), SkIntToScalar(0));
- points[1].set(SkIntToScalar(0), SkIntToScalar(height()));
-
- SkShader* shader = SkGradientShader::CreateLinear(points,
- kGradientColors, kGradientPoints, arraysize(kGradientPoints),
- SkShader::kRepeat_TileMode);
- DCHECK(shader);
-
- SkPaint paint;
- paint.setShader(shader);
- shader->unref();
-
- paint.setStyle(SkPaint::kFill_Style);
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
-
- canvas->DrawRectInt(0, 0, width(), height(), paint);
-#else
- // This is the same as COLOR_TOOLBAR.
- canvas->GetSkCanvas()->drawColor(SkColorSetRGB(210, 225, 246),
- SkXfermode::kSrc_Mode);
#endif
}
diff --git a/views/controls/menu/menu_separator_aura.cc b/views/controls/menu/menu_separator_aura.cc
new file mode 100644
index 0000000..add1639
--- /dev/null
+++ b/views/controls/menu/menu_separator_aura.cc
@@ -0,0 +1,24 @@
+// Copyright (c) 2011 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.
+
+#include "views/controls/menu/menu_separator.h"
+
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gfx/canvas.h"
+#include "views/controls/menu/menu_config.h"
+
+namespace views {
+
+static const SkColor kSeparatorColor = SkColorSetARGB(50, 00, 00, 00);
+
+void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
+ canvas->DrawLineInt(kSeparatorColor, 0, height() / 2, width(), height() / 2);
+}
+
+gfx::Size MenuSeparator::GetPreferredSize() {
+ return gfx::Size(10, // Just in case we're the only item in a menu.
+ MenuConfig::instance().separator_height);
+}
+
+} // namespace views
diff --git a/views/views.gyp b/views/views.gyp
index 25c3ce1..f9f9616 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -111,6 +111,7 @@
'controls/menu/menu_2.h',
'controls/menu/menu_config.cc',
'controls/menu/menu_config.h',
+ 'controls/menu/menu_config_aura.cc',
'controls/menu/menu_config_linux.cc',
'controls/menu/menu_config_win.cc',
'controls/menu/menu_controller.cc',
@@ -126,6 +127,7 @@
'controls/menu/menu_host_root_view.h',
'controls/menu/menu_item_view.cc',
'controls/menu/menu_item_view.h',
+ 'controls/menu/menu_item_view_aura.cc',
'controls/menu/menu_item_view_linux.cc',
'controls/menu/menu_item_view_win.cc',
'controls/menu/menu_listener.h',
@@ -136,6 +138,7 @@
'controls/menu/menu_scroll_view_container.cc',
'controls/menu/menu_scroll_view_container.h',
'controls/menu/menu_separator.h',
+ 'controls/menu/menu_separator_aura.cc',
'controls/menu/menu_separator_linux.cc',
'controls/menu/menu_separator_win.cc',
'controls/menu/menu_win.cc',
@@ -151,8 +154,8 @@
'controls/menu/native_menu_win.h',
'controls/menu/nested_dispatcher_gtk.cc',
'controls/menu/nested_dispatcher_gtk.h',
- 'controls/menu/menu_image_util_linux.cc',
- 'controls/menu/menu_image_util_linux.h',
+ 'controls/menu/menu_image_util.cc',
+ 'controls/menu/menu_image_util.h',
'controls/menu/submenu_view.cc',
'controls/menu/submenu_view.h',
'controls/menu/view_menu_delegate.h',
@@ -434,6 +437,9 @@
['exclude', 'controls/menu/menu_2.*'],
],
'sources!': [
+ 'controls/menu/menu_config_linux.cc',
+ 'controls/menu/menu_item_view_linux.cc',
+ 'controls/menu/menu_separator_linux.cc',
'controls/native_control.cc',
'controls/native_control.h',
'controls/scrollbar/bitmap_scroll_bar.cc',
@@ -459,9 +465,6 @@
'conditions': [
['OS=="win"', {
'sources/': [
- ['include', 'controls/menu/menu_config_win.cc'],
- ['include', 'controls/menu/menu_item_view_win.cc'],
- ['include', 'controls/menu/menu_separator_win.cc'],
['include', 'drag_utils_win.cc'],
],
}],