From 5964b17f51e9a6757925ba73ace6f4b276914e30 Mon Sep 17 00:00:00 2001 From: "jamescook@chromium.org" Date: Tue, 18 Oct 2011 16:22:50 +0000 Subject: Aura: Use same views menu setup on win_aura and linux_aura Resolves some TODOs I added in menu_config_win.cc and menu_item_view_win.cc, and harmonizes our menu rendering code between windows and linux Aura. BUG=100586 TEST=manual Review URL: http://codereview.chromium.org/8302017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106068 0039d316-1c4b-4281-b951-d872f2087c98 --- views/controls/menu/menu_config_aura.cc | 30 ++++++ views/controls/menu/menu_config_win.cc | 5 - views/controls/menu/menu_image_util.cc | 115 ++++++++++++++++++++++ views/controls/menu/menu_image_util.h | 24 +++++ views/controls/menu/menu_image_util_linux.cc | 115 ---------------------- views/controls/menu/menu_image_util_linux.h | 24 ----- views/controls/menu/menu_item_view.cc | 25 +++++ views/controls/menu/menu_item_view_aura.cc | 107 ++++++++++++++++++++ views/controls/menu/menu_item_view_linux.cc | 27 +---- views/controls/menu/menu_item_view_win.cc | 21 ---- views/controls/menu/menu_scroll_view_container.cc | 42 +------- views/controls/menu/menu_separator_aura.cc | 24 +++++ 12 files changed, 330 insertions(+), 229 deletions(-) create mode 100644 views/controls/menu/menu_config_aura.cc create mode 100644 views/controls/menu/menu_image_util.cc create mode 100644 views/controls/menu/menu_image_util.h delete mode 100644 views/controls/menu/menu_image_util_linux.cc delete mode 100644 views/controls/menu/menu_image_util_linux.h create mode 100644 views/controls/menu/menu_item_view_aura.cc create mode 100644 views/controls/menu/menu_separator_aura.cc (limited to 'views/controls/menu') 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.cc b/views/controls/menu/menu_image_util.cc new file mode 100644 index 0000000..e9b4b81 --- /dev/null +++ b/views/controls/menu/menu_image_util.cc @@ -0,0 +1,115 @@ +// 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_image_util.h" + +#include "base/i18n/rtl.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" + +namespace { + +// Size of the radio button inciator. +const int kSelectedIndicatorSize = 5; +const int kIndicatorSize = 10; + +// Used for the radio indicator. See theme_draw for details. +const double kGradientStop = .5; +const SkColor kGradient0 = SkColorSetRGB(255, 255, 255); +const SkColor kGradient1 = SkColorSetRGB(255, 255, 255); +const SkColor kGradient2 = SkColorSetRGB(0xD8, 0xD8, 0xD8); +const SkColor kBaseStroke = SkColorSetRGB(0x8F, 0x8F, 0x8F); +const SkColor kRadioButtonIndicatorGradient0 = SkColorSetRGB(0, 0, 0); +const SkColor kRadioButtonIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83); +const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); + +SkBitmap* CreateRadioButtonImage(bool selected) { + // + 2 (1px on each side) to cover rounding error. + gfx::CanvasSkia canvas(kIndicatorSize + 2, kIndicatorSize + 2, false); + canvas.TranslateInt(1, 1); + + SkPoint gradient_points[3]; + gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); + gradient_points[1].set( + SkIntToScalar(0), + SkIntToScalar(static_cast(kIndicatorSize * kGradientStop))); + gradient_points[2].set(SkIntToScalar(0), SkIntToScalar(kIndicatorSize)); + SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; + SkShader* shader = SkGradientShader::CreateLinear( + gradient_points, gradient_colors, NULL, arraysize(gradient_points), + SkShader::kClamp_TileMode, NULL); + SkPaint paint; + paint.setStyle(SkPaint::kFill_Style); + paint.setAntiAlias(true); + paint.setShader(shader); + shader->unref(); + int radius = kIndicatorSize / 2; + canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); + + paint.setStrokeWidth(SkIntToScalar(0)); + paint.setShader(NULL); + paint.setStyle(SkPaint::kStroke_Style); + paint.setColor(kBaseStroke); + canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); + + if (selected) { + SkPoint selected_gradient_points[2]; + selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); + selected_gradient_points[1].set( + SkIntToScalar(0), + SkIntToScalar(kSelectedIndicatorSize)); + SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, + kRadioButtonIndicatorGradient1 }; + shader = SkGradientShader::CreateLinear( + selected_gradient_points, selected_gradient_colors, NULL, + arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); + paint.setShader(shader); + shader->unref(); + paint.setStyle(SkPaint::kFill_Style); + canvas.sk_canvas()->drawCircle(radius, radius, + kSelectedIndicatorSize / 2, paint); + + paint.setStrokeWidth(SkIntToScalar(0)); + paint.setShader(NULL); + paint.setStyle(SkPaint::kStroke_Style); + paint.setColor(kIndicatorStroke); + canvas.sk_canvas()->drawCircle(radius, radius, + kSelectedIndicatorSize / 2, paint); + } + return new SkBitmap(canvas.ExtractBitmap()); +} + +SkBitmap* GetRtlSubmenuArrowImage() { + static SkBitmap* kRtlArrow = NULL; + if (!kRtlArrow) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + SkBitmap* r = rb.GetBitmapNamed(IDR_MENU_ARROW); + gfx::CanvasSkia canvas(r->width(), r->height(), false); + canvas.ScaleInt(-1, 1); + canvas.DrawBitmapInt(*r, - r->width(), 0); + kRtlArrow = new SkBitmap(canvas.ExtractBitmap()); + } + return kRtlArrow; +} + +} // namespace + +namespace views { + +const SkBitmap* GetRadioButtonImage(bool selected) { + static const SkBitmap* kRadioOn = CreateRadioButtonImage(true); + static const SkBitmap* kRadioOff = CreateRadioButtonImage(false); + + return selected ? kRadioOn : kRadioOff; +} + +const SkBitmap* GetSubmenuArrowImage() { + return base::i18n::IsRTL() ? + GetRtlSubmenuArrowImage() : + ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_MENU_ARROW); +} + +} // namespace views; diff --git a/views/controls/menu/menu_image_util.h b/views/controls/menu/menu_image_util.h new file mode 100644 index 0000000..bcf62fb --- /dev/null +++ b/views/controls/menu/menu_image_util.h @@ -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. + +#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" + +namespace views { + +// Return the RadioButton image for given state. +// It returns the "selected" image when |selected| is +// true, or the "unselected" image if false. +// The returned image is global object and should not be freed. +const SkBitmap* GetRadioButtonImage(bool selected); + +// Returns the image for submenu arrow for current RTL setting. +const SkBitmap* GetSubmenuArrowImage(); + +} // namespace views + +#endif // VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_H_ diff --git a/views/controls/menu/menu_image_util_linux.cc b/views/controls/menu/menu_image_util_linux.cc deleted file mode 100644 index f3e3e3a..0000000 --- a/views/controls/menu/menu_image_util_linux.cc +++ /dev/null @@ -1,115 +0,0 @@ -// 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_image_util_linux.h" - -#include "base/i18n/rtl.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" - -namespace { - -// Size of the radio button inciator. -const int kSelectedIndicatorSize = 5; -const int kIndicatorSize = 10; - -// Used for the radio indicator. See theme_draw for details. -const double kGradientStop = .5; -const SkColor kGradient0 = SkColorSetRGB(255, 255, 255); -const SkColor kGradient1 = SkColorSetRGB(255, 255, 255); -const SkColor kGradient2 = SkColorSetRGB(0xD8, 0xD8, 0xD8); -const SkColor kBaseStroke = SkColorSetRGB(0x8F, 0x8F, 0x8F); -const SkColor kRadioButtonIndicatorGradient0 = SkColorSetRGB(0, 0, 0); -const SkColor kRadioButtonIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83); -const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); - -SkBitmap* CreateRadioButtonImage(bool selected) { - // + 2 (1px on each side) to cover rounding error. - gfx::CanvasSkia canvas(kIndicatorSize + 2, kIndicatorSize + 2, false); - canvas.TranslateInt(1, 1); - - SkPoint gradient_points[3]; - gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); - gradient_points[1].set( - SkIntToScalar(0), - SkIntToScalar(static_cast(kIndicatorSize * kGradientStop))); - gradient_points[2].set(SkIntToScalar(0), SkIntToScalar(kIndicatorSize)); - SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; - SkShader* shader = SkGradientShader::CreateLinear( - gradient_points, gradient_colors, NULL, arraysize(gradient_points), - SkShader::kClamp_TileMode, NULL); - SkPaint paint; - paint.setStyle(SkPaint::kFill_Style); - paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); - int radius = kIndicatorSize / 2; - canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); - - paint.setStrokeWidth(SkIntToScalar(0)); - paint.setShader(NULL); - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(kBaseStroke); - canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); - - if (selected) { - SkPoint selected_gradient_points[2]; - selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); - selected_gradient_points[1].set( - SkIntToScalar(0), - SkIntToScalar(kSelectedIndicatorSize)); - SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, - kRadioButtonIndicatorGradient1 }; - shader = SkGradientShader::CreateLinear( - selected_gradient_points, selected_gradient_colors, NULL, - arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); - paint.setShader(shader); - shader->unref(); - paint.setStyle(SkPaint::kFill_Style); - canvas.sk_canvas()->drawCircle(radius, radius, - kSelectedIndicatorSize / 2, paint); - - paint.setStrokeWidth(SkIntToScalar(0)); - paint.setShader(NULL); - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(kIndicatorStroke); - canvas.sk_canvas()->drawCircle(radius, radius, - kSelectedIndicatorSize / 2, paint); - } - return new SkBitmap(canvas.ExtractBitmap()); -} - -SkBitmap* GetRtlSubmenuArrowImage() { - static SkBitmap* kRtlArrow = NULL; - if (!kRtlArrow) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SkBitmap* r = rb.GetBitmapNamed(IDR_MENU_ARROW); - gfx::CanvasSkia canvas(r->width(), r->height(), false); - canvas.ScaleInt(-1, 1); - canvas.DrawBitmapInt(*r, - r->width(), 0); - kRtlArrow = new SkBitmap(canvas.ExtractBitmap()); - } - return kRtlArrow; -} - -} // namespace - -namespace views { - -const SkBitmap* GetRadioButtonImage(bool selected) { - static const SkBitmap* kRadioOn = CreateRadioButtonImage(true); - static const SkBitmap* kRadioOff = CreateRadioButtonImage(false); - - return selected ? kRadioOn : kRadioOff; -} - -const SkBitmap* GetSubmenuArrowImage() { - return base::i18n::IsRTL() ? - GetRtlSubmenuArrowImage() : - ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_MENU_ARROW); -} - -} // namespace views; diff --git a/views/controls/menu/menu_image_util_linux.h b/views/controls/menu/menu_image_util_linux.h deleted file mode 100644 index abf9bcb..0000000 --- a/views/controls/menu/menu_image_util_linux.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -#ifndef VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_H_ -#define VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_H_ -#pragma once - -#include "third_party/skia/include/core/SkBitmap.h" - -namespace views { - -// Return the RadioButton image for given state. -// It returns the "selected" image when |selected| is -// true, or the "unselected" image if false. -// The returned image is global object and should not be freed. -const SkBitmap* GetRadioButtonImage(bool selected); - -// Returns the image for submenu arrow for current RTL setting. -const SkBitmap* GetSubmenuArrowImage(); - -} // namespace views - -#endif // VIEWS_CONTROLS_MENU_MENU_IMAGE_UTIL_LINUX_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 -- cgit v1.1