| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 35 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
| 36 #include "third_party/skia/include/core/SkCanvas.h" | 36 #include "third_party/skia/include/core/SkCanvas.h" |
| 37 #include "third_party/skia/include/core/SkPaint.h" | 37 #include "third_party/skia/include/core/SkPaint.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/layout.h" | 39 #include "ui/base/layout.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/image/canvas_image_source.h" | |
| 43 #include "ui/gfx/image/image.h" | 42 #include "ui/gfx/image/image.h" |
| 43 #include "ui/gfx/image/image_skia_source.h" |
| 44 #include "ui/gfx/skia_util.h" | 44 #include "ui/gfx/skia_util.h" |
| 45 #include "ui/gfx/text_utils.h" | 45 #include "ui/gfx/text_utils.h" |
| 46 #include "ui/views/background.h" | 46 #include "ui/views/background.h" |
| 47 #include "ui/views/controls/button/image_button.h" | 47 #include "ui/views/controls/button/image_button.h" |
| 48 #include "ui/views/controls/button/label_button.h" | 48 #include "ui/views/controls/button/label_button.h" |
| 49 #include "ui/views/controls/button/menu_button.h" | 49 #include "ui/views/controls/button/menu_button.h" |
| 50 #include "ui/views/controls/label.h" | 50 #include "ui/views/controls/label.h" |
| 51 #include "ui/views/controls/menu/menu_config.h" | 51 #include "ui/views/controls/menu/menu_config.h" |
| 52 #include "ui/views/controls/menu/menu_item_view.h" | 52 #include "ui/views/controls/menu/menu_item_view.h" |
| 53 #include "ui/views/controls/menu/menu_model_adapter.h" | 53 #include "ui/views/controls/menu/menu_model_adapter.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 using views::CustomButton; | 67 using views::CustomButton; |
| 68 using views::ImageButton; | 68 using views::ImageButton; |
| 69 using views::Label; | 69 using views::Label; |
| 70 using views::LabelButton; | 70 using views::LabelButton; |
| 71 using views::MenuConfig; | 71 using views::MenuConfig; |
| 72 using views::MenuItemView; | 72 using views::MenuItemView; |
| 73 using views::View; | 73 using views::View; |
| 74 | 74 |
| 75 namespace { | 75 namespace { |
| 76 | 76 |
| 77 // Colors used for buttons. | |
| 78 const SkColor kEnabledTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); | |
| 79 const SkColor kHoverTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); | |
| 80 const SkColor kFocusedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); | |
| 81 | |
| 82 const SkColor kTouchButtonText = 0xff5a5a5a; | |
| 83 | |
| 84 // Horizontal padding on the edges of the buttons. | 77 // Horizontal padding on the edges of the buttons. |
| 85 const int kHorizontalPadding = 6; | 78 const int kHorizontalPadding = 6; |
| 86 // Horizontal padding for a touch enabled menu. | 79 // Horizontal padding for a touch enabled menu. |
| 87 const int kHorizontalTouchPadding = 15; | 80 const int kHorizontalTouchPadding = 15; |
| 88 | 81 |
| 89 // Menu items which have embedded buttons should have this height in pixel. | 82 // Menu items which have embedded buttons should have this height in pixel. |
| 90 const int kMenuItemContainingButtonsHeight = 43; | 83 const int kMenuItemContainingButtonsHeight = 43; |
| 91 | 84 |
| 92 // Returns true if |command_id| identifies a bookmark menu item. | 85 // Returns true if |command_id| identifies a bookmark menu item. |
| 93 bool IsBookmarkCommand(int command_id) { | 86 bool IsBookmarkCommand(int command_id) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 left_button_ = right_button; | 174 left_button_ = right_button; |
| 182 right_button_ = left_button; | 175 right_button_ = left_button; |
| 183 } else { | 176 } else { |
| 184 left_button_ = left_button; | 177 left_button_ = left_button; |
| 185 right_button_ = right_button; | 178 right_button_ = right_button; |
| 186 } | 179 } |
| 187 } | 180 } |
| 188 | 181 |
| 189 // Overridden from views::Background. | 182 // Overridden from views::Background. |
| 190 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { | 183 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { |
| 191 CustomButton::ButtonState state = | 184 CustomButton* button = CustomButton::AsCustomButton(view); |
| 192 (!strcmp(view->GetClassName(), views::Label::kViewClassName)) ? | 185 views::Button::ButtonState state = |
| 193 CustomButton::STATE_NORMAL : static_cast<CustomButton*>(view)->state(); | 186 button ? button->state() : views::Button::STATE_NORMAL; |
| 194 int w = view->width(); | 187 int w = view->width(); |
| 195 int h = view->height(); | 188 int h = view->height(); |
| 196 #if defined(USE_AURA) | 189 #if defined(USE_AURA) |
| 197 if (use_new_menu_ && | 190 // Normal buttons get a border drawn on the right side and the rest gets |
| 198 view->GetNativeTheme() == ui::NativeThemeAura::instance()) { | 191 // filled in. The left button however does not get a line to combine |
| 199 // Normal buttons get a border drawn on the right side and the rest gets | 192 // buttons. |
| 200 // filled in. The left button however does not get a line to combine | 193 int border = 0; |
| 201 // buttons. | 194 if (type_ != RIGHT_BUTTON) { |
| 202 int border = 0; | 195 border = 1; |
| 203 if (type_ != RIGHT_BUTTON) { | 196 canvas->FillRect(gfx::Rect(0, 0, border, h), |
| 204 border = 1; | 197 BorderColor(view, views::Button::STATE_NORMAL)); |
| 205 canvas->FillRect(gfx::Rect(0, 0, border, h), | 198 } |
| 206 BorderColor(view, CustomButton::STATE_NORMAL)); | 199 if (use_new_menu_) { |
| 207 } | 200 gfx::Rect bounds(view->GetLocalBounds()); |
| 208 canvas->FillRect(gfx::Rect(border, 0, w - border, h), | 201 bounds.set_x(view->GetMirroredXForRect(bounds)); |
| 209 touch_background_color(state)); | 202 DrawBackground(canvas, view, bounds, state); |
| 210 return; | 203 return; |
| 211 } | 204 } |
| 212 #endif | 205 #endif |
| 213 const SkColor background = BackgroundColor(view, state); | 206 const SkColor border_color = BorderColor(view, state); |
| 214 const SkColor border = BorderColor(view, state); | |
| 215 switch (TypeAdjustedForRTL()) { | 207 switch (TypeAdjustedForRTL()) { |
| 216 // TODO(pkasting): Why don't all the following use SkPaths with rounded | 208 // TODO(pkasting): Why don't all the following use SkPaths with rounded |
| 217 // corners? | 209 // corners? |
| 218 case LEFT_BUTTON: | 210 case LEFT_BUTTON: |
| 219 canvas->FillRect(gfx::Rect(1, 1, w, h - 2), background); | 211 DrawBackground(canvas, view, gfx::Rect(1, 1, w, h - 2), state); |
| 220 canvas->FillRect(gfx::Rect(2, 0, w, 1), border); | 212 canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color); |
| 221 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); | 213 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
| 222 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); | 214 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
| 223 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); | 215 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
| 224 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border); | 216 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color); |
| 225 break; | 217 break; |
| 226 | 218 |
| 227 case CENTER_BUTTON: { | 219 case CENTER_BUTTON: { |
| 228 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); | 220 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
| 229 SkColor left_color = state != CustomButton::STATE_NORMAL ? | 221 SkColor left_color = state != views::Button::STATE_NORMAL ? |
| 230 border : BorderColor(view, left_button_->state()); | 222 border_color : BorderColor(view, left_button_->state()); |
| 231 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); | 223 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); |
| 232 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border); | 224 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color); |
| 233 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), | 225 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), |
| 234 border); | 226 border_color); |
| 235 SkColor right_color = state != CustomButton::STATE_NORMAL ? | 227 SkColor right_color = state != views::Button::STATE_NORMAL ? |
| 236 border : BorderColor(view, right_button_->state()); | 228 border_color : BorderColor(view, right_button_->state()); |
| 237 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); | 229 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); |
| 238 break; | 230 break; |
| 239 } | 231 } |
| 240 | 232 |
| 241 case RIGHT_BUTTON: | 233 case RIGHT_BUTTON: |
| 242 canvas->FillRect(gfx::Rect(0, 1, w - 1, h - 2), background); | 234 DrawBackground(canvas, view, gfx::Rect(0, 1, w - 1, h - 2), state); |
| 243 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border); | 235 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color); |
| 244 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); | 236 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
| 245 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); | 237 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
| 246 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); | 238 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
| 247 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border); | 239 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color); |
| 248 break; | 240 break; |
| 249 | 241 |
| 250 case SINGLE_BUTTON: | 242 case SINGLE_BUTTON: |
| 251 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); | 243 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
| 252 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border); | 244 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color); |
| 253 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); | 245 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
| 254 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); | 246 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
| 255 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); | 247 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
| 256 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border); | 248 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color); |
| 257 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); | 249 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
| 258 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); | 250 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
| 259 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); | 251 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
| 260 break; | 252 break; |
| 261 | 253 |
| 262 default: | 254 default: |
| 263 NOTREACHED(); | 255 NOTREACHED(); |
| 264 break; | 256 break; |
| 265 } | 257 } |
| 266 } | 258 } |
| 267 | 259 |
| 268 private: | 260 private: |
| 269 static SkColor BorderColor(View* view, CustomButton::ButtonState state) { | 261 static SkColor BorderColor(View* view, views::Button::ButtonState state) { |
| 270 ui::NativeTheme* theme = view->GetNativeTheme(); | 262 ui::NativeTheme* theme = view->GetNativeTheme(); |
| 271 switch (state) { | 263 switch (state) { |
| 272 case CustomButton::STATE_HOVERED: | 264 case views::Button::STATE_HOVERED: |
| 273 return theme->GetSystemColor( | 265 return theme->GetSystemColor( |
| 274 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); | 266 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); |
| 275 case CustomButton::STATE_PRESSED: | 267 case views::Button::STATE_PRESSED: |
| 276 return theme->GetSystemColor( | 268 return theme->GetSystemColor( |
| 277 ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor); | 269 ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor); |
| 278 default: | 270 default: |
| 279 return theme->GetSystemColor( | 271 return theme->GetSystemColor( |
| 280 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor); | 272 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor); |
| 281 } | 273 } |
| 282 } | 274 } |
| 283 | 275 |
| 284 static SkColor BackgroundColor(View* view, CustomButton::ButtonState state) { | 276 static SkColor BackgroundColor(const View* view, |
| 285 ui::NativeTheme* theme = view->GetNativeTheme(); | 277 views::Button::ButtonState state) { |
| 278 const ui::NativeTheme* theme = view->GetNativeTheme(); |
| 286 switch (state) { | 279 switch (state) { |
| 287 case CustomButton::STATE_HOVERED: | 280 case views::Button::STATE_HOVERED: |
| 281 // Hovered should be handled in DrawBackground. |
| 282 NOTREACHED(); |
| 288 return theme->GetSystemColor( | 283 return theme->GetSystemColor( |
| 289 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); | 284 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); |
| 290 case CustomButton::STATE_PRESSED: | 285 case views::Button::STATE_PRESSED: |
| 291 return theme->GetSystemColor( | 286 return theme->GetSystemColor( |
| 292 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 287 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
| 293 default: | 288 default: |
| 294 return theme->GetSystemColor( | 289 return theme->GetSystemColor( |
| 295 ui::NativeTheme::kColorId_MenuBackgroundColor); | 290 ui::NativeTheme::kColorId_MenuBackgroundColor); |
| 296 } | 291 } |
| 297 } | 292 } |
| 298 | 293 |
| 299 static SkColor touch_background_color(CustomButton::ButtonState state) { | 294 void DrawBackground(gfx::Canvas* canvas, |
| 300 switch (state) { | 295 const views::View* view, |
| 301 case CustomButton::STATE_HOVERED: return kHoverTouchBackgroundColor; | 296 const gfx::Rect& bounds, |
| 302 case CustomButton::STATE_PRESSED: return kFocusedTouchBackgroundColor; | 297 views::Button::ButtonState state) const { |
| 303 default: return kEnabledTouchBackgroundColor; | 298 if (state == views::Button::STATE_HOVERED) { |
| 299 view->GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 300 ui::NativeTheme::kMenuItemBackground, |
| 301 ui::NativeTheme::kHovered, |
| 302 bounds, |
| 303 ui::NativeTheme::ExtraParams()); |
| 304 return; |
| 304 } | 305 } |
| 306 if (use_new_menu_) |
| 307 return; |
| 308 canvas->FillRect(bounds, BackgroundColor(view, state)); |
| 305 } | 309 } |
| 306 | 310 |
| 307 ButtonType TypeAdjustedForRTL() const { | 311 ButtonType TypeAdjustedForRTL() const { |
| 308 if (!base::i18n::IsRTL()) | 312 if (!base::i18n::IsRTL()) |
| 309 return type_; | 313 return type_; |
| 310 | 314 |
| 311 switch (type_) { | 315 switch (type_) { |
| 312 case LEFT_BUTTON: return RIGHT_BUTTON; | 316 case LEFT_BUTTON: return RIGHT_BUTTON; |
| 313 case RIGHT_BUTTON: return LEFT_BUTTON; | 317 case RIGHT_BUTTON: return LEFT_BUTTON; |
| 314 default: break; | 318 default: break; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // Overridden from views::View. | 365 // Overridden from views::View. |
| 362 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { | 366 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { |
| 363 // Normally when the mouse enters/exits a button the buttons invokes | 367 // Normally when the mouse enters/exits a button the buttons invokes |
| 364 // SchedulePaint. As part of the button border (MenuButtonBackground) is | 368 // SchedulePaint. As part of the button border (MenuButtonBackground) is |
| 365 // rendered by the button to the left/right of it SchedulePaint on the the | 369 // rendered by the button to the left/right of it SchedulePaint on the the |
| 366 // button may not be enough, so this forces a paint all. | 370 // button may not be enough, so this forces a paint all. |
| 367 View::SchedulePaintInRect(gfx::Rect(size())); | 371 View::SchedulePaintInRect(gfx::Rect(size())); |
| 368 } | 372 } |
| 369 | 373 |
| 370 LabelButton* CreateAndConfigureButton(int string_id, | 374 LabelButton* CreateAndConfigureButton(int string_id, |
| 371 MenuButtonBackground::ButtonType type, | 375 MenuButtonBackground::ButtonType type, |
| 372 int index, | 376 int index, |
| 373 MenuButtonBackground** background) { | 377 MenuButtonBackground** background) { |
| 374 return CreateButtonWithAccName( | 378 return CreateButtonWithAccName( |
| 375 string_id, type, index, background, string_id); | 379 string_id, type, index, background, string_id); |
| 376 } | 380 } |
| 377 | 381 |
| 378 LabelButton* CreateButtonWithAccName(int string_id, | 382 LabelButton* CreateButtonWithAccName(int string_id, |
| 379 MenuButtonBackground::ButtonType type, | 383 MenuButtonBackground::ButtonType type, |
| 380 int index, | 384 int index, |
| 381 MenuButtonBackground** background, | 385 MenuButtonBackground** background, |
| 382 int acc_string_id) { | 386 int acc_string_id) { |
| 383 // Should only be invoked during construction when |menu_| is valid. | 387 // Should only be invoked during construction when |menu_| is valid. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 394 new MenuButtonBackground(type, menu_->use_new_menu()); | 398 new MenuButtonBackground(type, menu_->use_new_menu()); |
| 395 button->set_background(bg); | 399 button->set_background(bg); |
| 396 const MenuConfig& menu_config = menu_->GetMenuConfig(); | 400 const MenuConfig& menu_config = menu_->GetMenuConfig(); |
| 397 button->SetTextColor(views::Button::STATE_NORMAL, menu_config.text_color); | 401 button->SetTextColor(views::Button::STATE_NORMAL, menu_config.text_color); |
| 398 if (background) | 402 if (background) |
| 399 *background = bg; | 403 *background = bg; |
| 400 button->set_border( | 404 button->set_border( |
| 401 new MenuButtonBorder(menu_config, menu_->use_new_menu())); | 405 new MenuButtonBorder(menu_config, menu_->use_new_menu())); |
| 402 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 406 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 403 button->SetFont(menu_config.font); | 407 button->SetFont(menu_config.font); |
| 408 ui::NativeTheme* native_theme = button->GetNativeTheme(); |
| 409 button->SetTextColor( |
| 410 views::Button::STATE_DISABLED, |
| 411 native_theme->GetSystemColor( |
| 412 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); |
| 413 button->SetTextColor( |
| 414 views::Button::STATE_HOVERED, |
| 415 native_theme->GetSystemColor( |
| 416 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
| 417 button->SetTextColor( |
| 418 views::Button::STATE_PRESSED, |
| 419 native_theme->GetSystemColor( |
| 420 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
| 421 button->SetTextColor( |
| 422 views::Button::STATE_NORMAL, |
| 423 native_theme->GetSystemColor( |
| 424 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
| 404 AddChildView(button); | 425 AddChildView(button); |
| 426 // all buttons on menu should must be a custom button in order for |
| 427 // the keyboard nativigation work. |
| 428 DCHECK(CustomButton::AsCustomButton(button)); |
| 405 return button; | 429 return button; |
| 406 } | 430 } |
| 407 | 431 |
| 408 // Overridden from WrenchMenuObserver: | 432 // Overridden from WrenchMenuObserver: |
| 409 virtual void WrenchMenuDestroyed() OVERRIDE { | 433 virtual void WrenchMenuDestroyed() OVERRIDE { |
| 410 menu_->RemoveObserver(this); | 434 menu_->RemoveObserver(this); |
| 411 menu_ = NULL; | 435 menu_ = NULL; |
| 412 menu_model_ = NULL; | 436 menu_model_ = NULL; |
| 413 } | 437 } |
| 414 | 438 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 size.set_height(height); | 472 size.set_height(height); |
| 449 return size; | 473 return size; |
| 450 } | 474 } |
| 451 | 475 |
| 452 private: | 476 private: |
| 453 int height_; | 477 int height_; |
| 454 | 478 |
| 455 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); | 479 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); |
| 456 }; | 480 }; |
| 457 | 481 |
| 482 // Generate the button image for hover state. |
| 483 class HoveredImageSource : public gfx::ImageSkiaSource { |
| 484 public: |
| 485 HoveredImageSource(const gfx::ImageSkia& image, SkColor color) |
| 486 : image_(image), |
| 487 color_(color) { |
| 488 } |
| 489 virtual ~HoveredImageSource() {} |
| 490 |
| 491 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 492 const gfx::ImageSkiaRep& rep = image_.GetRepresentation(scale); |
| 493 SkBitmap bitmap = rep.sk_bitmap(); |
| 494 SkBitmap white; |
| 495 white.setConfig(SkBitmap::kARGB_8888_Config, |
| 496 bitmap.width(), bitmap.height(), 0); |
| 497 white.allocPixels(); |
| 498 white.eraseARGB(0, 0, 0, 0); |
| 499 bitmap.lockPixels(); |
| 500 for (int y = 0; y < bitmap.height(); ++y) { |
| 501 uint32* image_row = bitmap.getAddr32(0, y); |
| 502 uint32* dst_row = white.getAddr32(0, y); |
| 503 for (int x = 0; x < bitmap.width(); ++x) { |
| 504 uint32 image_pixel = image_row[x]; |
| 505 // Fill the non transparent pixels with |color_|. |
| 506 dst_row[x] = (image_pixel & 0xFF000000) == 0x0 ? 0x0 : color_; |
| 507 } |
| 508 } |
| 509 bitmap.unlockPixels(); |
| 510 return gfx::ImageSkiaRep(white, scale); |
| 511 } |
| 512 |
| 513 private: |
| 514 const gfx::ImageSkia image_; |
| 515 const SkColor color_; |
| 516 DISALLOW_COPY_AND_ASSIGN(HoveredImageSource); |
| 517 }; |
| 518 |
| 458 } // namespace | 519 } // namespace |
| 459 | 520 |
| 460 // CutCopyPasteView ------------------------------------------------------------ | 521 // CutCopyPasteView ------------------------------------------------------------ |
| 461 | 522 |
| 462 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 523 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
| 463 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 524 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
| 464 public: | 525 public: |
| 465 CutCopyPasteView(WrenchMenu* menu, | 526 CutCopyPasteView(WrenchMenu* menu, |
| 466 MenuModel* menu_model, | 527 MenuModel* menu_model, |
| 467 const ui::NativeTheme* native_theme, | 528 const ui::NativeTheme* native_theme, |
| 468 int cut_index, | 529 int cut_index, |
| 469 int copy_index, | 530 int copy_index, |
| 470 int paste_index) | 531 int paste_index) |
| 471 : WrenchMenuView(menu, menu_model) { | 532 : WrenchMenuView(menu, menu_model) { |
| 472 LabelButton* cut = CreateAndConfigureButton( | 533 LabelButton* cut = CreateAndConfigureButton( |
| 473 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); | 534 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); |
| 474 | |
| 475 MenuButtonBackground* copy_background = NULL; | 535 MenuButtonBackground* copy_background = NULL; |
| 476 LabelButton* copy = CreateAndConfigureButton( | 536 CreateAndConfigureButton( |
| 477 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, | 537 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, |
| 478 ©_background); | 538 ©_background); |
| 479 | |
| 480 LabelButton* paste = CreateAndConfigureButton( | 539 LabelButton* paste = CreateAndConfigureButton( |
| 481 IDS_PASTE, | 540 IDS_PASTE, |
| 482 menu->use_new_menu() && menu->supports_new_separators_ ? | 541 menu->use_new_menu() && menu->supports_new_separators_ ? |
| 483 MenuButtonBackground::CENTER_BUTTON : | 542 MenuButtonBackground::CENTER_BUTTON : |
| 484 MenuButtonBackground::RIGHT_BUTTON, | 543 MenuButtonBackground::RIGHT_BUTTON, |
| 485 paste_index, | 544 paste_index, |
| 486 NULL); | 545 NULL); |
| 487 if (menu->use_new_menu()) { | |
| 488 cut->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
| 489 copy->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
| 490 paste->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
| 491 } else { | |
| 492 SkColor text_color = native_theme->GetSystemColor( | |
| 493 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | |
| 494 cut->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
| 495 copy->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
| 496 paste->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
| 497 } | |
| 498 copy_background->SetOtherButtons(cut, paste); | 546 copy_background->SetOtherButtons(cut, paste); |
| 499 } | 547 } |
| 500 | 548 |
| 501 // Overridden from View. | 549 // Overridden from View. |
| 502 virtual gfx::Size GetPreferredSize() OVERRIDE { | 550 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 503 // Returned height doesn't matter as MenuItemView forces everything to the | 551 // Returned height doesn't matter as MenuItemView forces everything to the |
| 504 // height of the menuitemview. | 552 // height of the menuitemview. |
| 505 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); | 553 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); |
| 506 } | 554 } |
| 507 | 555 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 AddChildView(zoom_label_); | 630 AddChildView(zoom_label_); |
| 583 zoom_label_width_ = MaxWidthForZoomLabel(); | 631 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 584 | 632 |
| 585 increment_button_ = CreateButtonWithAccName( | 633 increment_button_ = CreateButtonWithAccName( |
| 586 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, | 634 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, |
| 587 NULL, IDS_ACCNAME_ZOOM_PLUS2); | 635 NULL, IDS_ACCNAME_ZOOM_PLUS2); |
| 588 | 636 |
| 589 center_bg->SetOtherButtons(decrement_button_, increment_button_); | 637 center_bg->SetOtherButtons(decrement_button_, increment_button_); |
| 590 | 638 |
| 591 fullscreen_button_ = new FullscreenButton(this); | 639 fullscreen_button_ = new FullscreenButton(this); |
| 640 // all buttons on menu should must be a custom button in order for |
| 641 // the keyboard nativigation work. |
| 642 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); |
| 592 gfx::ImageSkia* full_screen_image = | 643 gfx::ImageSkia* full_screen_image = |
| 593 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 644 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 594 IDR_FULLSCREEN_MENU_BUTTON); | 645 IDR_FULLSCREEN_MENU_BUTTON); |
| 595 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 646 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
| 596 if (menu->use_new_menu()) { | 647 SkColor fg_color = native_theme->GetSystemColor( |
| 597 zoom_label_->SetEnabledColor(kTouchButtonText); | 648 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); |
| 598 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 649 fullscreen_button_->SetImage( |
| 599 kTouchButtonText); | 650 ImageButton::STATE_HOVERED, |
| 600 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 651 new gfx::ImageSkia(new HoveredImageSource(*full_screen_image, fg_color), |
| 601 kTouchButtonText); | 652 full_screen_image->size())); |
| 602 } else { | 653 SkColor enabled_text_color = native_theme->GetSystemColor( |
| 603 SkColor enabled_text_color = native_theme->GetSystemColor( | 654 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
| 604 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | 655 zoom_label_->SetEnabledColor(enabled_text_color); |
| 605 zoom_label_->SetEnabledColor(enabled_text_color); | 656 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 606 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 657 enabled_text_color); |
| 607 enabled_text_color); | 658 increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 608 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 659 enabled_text_color); |
| 609 enabled_text_color); | 660 SkColor disabled_text_color = native_theme->GetSystemColor( |
| 610 SkColor disabled_text_color = native_theme->GetSystemColor( | 661 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
| 611 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | 662 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, |
| 612 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, | 663 disabled_text_color); |
| 613 disabled_text_color); | 664 increment_button_->SetTextColor(views::Button::STATE_DISABLED, |
| 614 increment_button_->SetTextColor(views::Button::STATE_DISABLED, | 665 disabled_text_color); |
| 615 disabled_text_color); | |
| 616 } | |
| 617 | |
| 618 fullscreen_button_->set_focusable(true); | 666 fullscreen_button_->set_focusable(true); |
| 619 fullscreen_button_->set_request_focus_on_press(false); | 667 fullscreen_button_->set_request_focus_on_press(false); |
| 620 fullscreen_button_->set_tag(fullscreen_index); | 668 fullscreen_button_->set_tag(fullscreen_index); |
| 621 fullscreen_button_->SetImageAlignment( | 669 fullscreen_button_->SetImageAlignment( |
| 622 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 670 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
| 623 int horizontal_padding = | 671 int horizontal_padding = |
| 624 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; | 672 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; |
| 625 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( | 673 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( |
| 626 0, horizontal_padding, 0, horizontal_padding)); | 674 0, horizontal_padding, 0, horizontal_padding)); |
| 627 fullscreen_button_->set_background( | 675 fullscreen_button_->set_background( |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 0, | 1359 0, |
| 1312 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1360 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1313 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1361 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1314 } | 1362 } |
| 1315 | 1363 |
| 1316 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1364 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
| 1317 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1365 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1318 DCHECK(ix != command_id_to_entry_.end()); | 1366 DCHECK(ix != command_id_to_entry_.end()); |
| 1319 return ix->second.second; | 1367 return ix->second.second; |
| 1320 } | 1368 } |
| OLD | NEW |