Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/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 18 matching lines...) Expand all Loading... | |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 33 #include "third_party/skia/include/core/SkCanvas.h" | 33 #include "third_party/skia/include/core/SkCanvas.h" |
| 34 #include "third_party/skia/include/core/SkPaint.h" | 34 #include "third_party/skia/include/core/SkPaint.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/layout.h" | 36 #include "ui/base/layout.h" |
| 37 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 38 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| 39 #include "ui/gfx/image/canvas_image_source.h" | |
| 39 #include "ui/gfx/skia_util.h" | 40 #include "ui/gfx/skia_util.h" |
| 40 #include "ui/views/background.h" | 41 #include "ui/views/background.h" |
| 41 #include "ui/views/controls/button/image_button.h" | 42 #include "ui/views/controls/button/image_button.h" |
| 42 #include "ui/views/controls/button/menu_button.h" | 43 #include "ui/views/controls/button/menu_button.h" |
| 43 #include "ui/views/controls/button/text_button.h" | 44 #include "ui/views/controls/button/text_button.h" |
| 44 #include "ui/views/controls/label.h" | 45 #include "ui/views/controls/label.h" |
| 45 #include "ui/views/controls/menu/menu_config.h" | 46 #include "ui/views/controls/menu/menu_config.h" |
| 46 #include "ui/views/controls/menu/menu_item_view.h" | 47 #include "ui/views/controls/menu/menu_item_view.h" |
| 47 #include "ui/views/controls/menu/menu_runner.h" | 48 #include "ui/views/controls/menu/menu_runner.h" |
| 48 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 49 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 size.set_height(height); | 390 size.set_height(height); |
| 390 return size; | 391 return size; |
| 391 } | 392 } |
| 392 | 393 |
| 393 private: | 394 private: |
| 394 int height_; | 395 int height_; |
| 395 | 396 |
| 396 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); | 397 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); |
| 397 }; | 398 }; |
| 398 | 399 |
| 399 gfx::ImageSkia* TintImage(gfx::ImageSkia* image, SkColor tint_value) { | 400 class TintedImageSource: public gfx::CanvasImageSource { |
| 400 // In case of touch, the menu needs to be brightened up a bit. | 401 public: |
| 401 // Create a new bitmap since we do not want to change the original image. | 402 TintedImageSource(gfx::ImageSkia& image, SkColor tint_value) |
| 402 SkBitmap bitmap_copy; | 403 : CanvasImageSource(image.size(), false), |
| 403 image->bitmap()->copyTo(&bitmap_copy, SkBitmap::kARGB_8888_Config); | 404 image_(image), |
| 404 SkCanvas canvas(bitmap_copy); | 405 tint_value_(tint_value) { |
| 405 SkPaint paint; | 406 } |
| 406 // We leave the old alpha alone and add the new color multiplied | 407 |
| 407 // with the source alpha to the existing alpha. Thus: We brighten | 408 virtual ~TintedImageSource() { |
| 408 // the image up - but only the non transparent pixels. | 409 } |
| 409 paint.setXfermodeMode(SkXfermode::kDstATop_Mode); | 410 |
| 410 paint.setColor(tint_value); | 411 void Draw(gfx::Canvas* canvas) OVERRIDE { |
| 411 canvas.drawPaint(paint); | 412 canvas->DrawImageInt(image_, 0, 0); |
| 412 return new gfx::ImageSkia(bitmap_copy); | 413 SkPaint paint; |
| 413 } | 414 paint.setXfermodeMode(SkXfermode::kDstATop_Mode); |
| 415 paint.setColor(tint_value_); | |
| 416 canvas->sk_canvas()->drawPaint(paint); | |
| 417 } | |
| 418 | |
| 419 private: | |
| 420 const gfx::ImageSkia image_; | |
| 421 const SkColor tint_value_; | |
| 422 }; | |
| 414 | 423 |
| 415 } // namespace | 424 } // namespace |
| 416 | 425 |
| 417 // CutCopyPasteView ------------------------------------------------------------ | 426 // CutCopyPasteView ------------------------------------------------------------ |
| 418 | 427 |
| 419 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 428 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
| 420 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 429 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
| 421 public: | 430 public: |
| 422 CutCopyPasteView(WrenchMenu* menu, | 431 CutCopyPasteView(WrenchMenu* menu, |
| 423 MenuModel* menu_model, | 432 MenuModel* menu_model, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, | 541 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, |
| 533 NULL, IDS_ACCNAME_ZOOM_PLUS2); | 542 NULL, IDS_ACCNAME_ZOOM_PLUS2); |
| 534 | 543 |
| 535 center_bg->SetOtherButtons(decrement_button_, increment_button_); | 544 center_bg->SetOtherButtons(decrement_button_, increment_button_); |
| 536 | 545 |
| 537 fullscreen_button_ = new FullscreenButton(this); | 546 fullscreen_button_ = new FullscreenButton(this); |
| 538 gfx::ImageSkia* full_screen_image = | 547 gfx::ImageSkia* full_screen_image = |
| 539 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 548 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 540 IDR_FULLSCREEN_MENU_BUTTON); | 549 IDR_FULLSCREEN_MENU_BUTTON); |
| 541 if (is_touch) { | 550 if (is_touch) { |
| 542 tinted_fullscreen_image_.reset(TintImage(full_screen_image, | 551 tinted_fullscreen_image_ = gfx::ImageSkia(new TintedImageSource( |
| 543 kTouchImageBrighten)); | 552 *full_screen_image, kTouchImageBrighten), full_screen_image->size()); |
| 544 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, | 553 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, |
| 545 tinted_fullscreen_image_.get()); | 554 new gfx::ImageSkia(tinted_fullscreen_image_)); |
|
sadrul
2012/07/17 03:30:08
I think this is leaking ... you could just send &t
| |
| 546 } else { | 555 } else { |
| 547 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image); | 556 fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image); |
| 548 } | 557 } |
| 549 if (is_touch) { | 558 if (is_touch) { |
| 550 zoom_label_->SetEnabledColor(kTouchButtonText); | 559 zoom_label_->SetEnabledColor(kTouchButtonText); |
| 551 decrement_button_->SetEnabledColor(kTouchButtonText); | 560 decrement_button_->SetEnabledColor(kTouchButtonText); |
| 552 increment_button_->SetEnabledColor(kTouchButtonText); | 561 increment_button_->SetEnabledColor(kTouchButtonText); |
| 553 } else { | 562 } else { |
| 554 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color); | 563 zoom_label_->SetEnabledColor(MenuConfig::instance().text_color); |
| 555 } | 564 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 | 711 |
| 703 // Label showing zoom as a percent. | 712 // Label showing zoom as a percent. |
| 704 Label* zoom_label_; | 713 Label* zoom_label_; |
| 705 | 714 |
| 706 // Button for decrementing the zoom. | 715 // Button for decrementing the zoom. |
| 707 TextButton* decrement_button_; | 716 TextButton* decrement_button_; |
| 708 | 717 |
| 709 ImageButton* fullscreen_button_; | 718 ImageButton* fullscreen_button_; |
| 710 | 719 |
| 711 // The tinted bitmap of the fullscreen button. | 720 // The tinted bitmap of the fullscreen button. |
| 712 scoped_ptr<gfx::ImageSkia> tinted_fullscreen_image_; | 721 gfx::ImageSkia tinted_fullscreen_image_; |
| 713 | 722 |
| 714 // Width given to |zoom_label_|. This is the width at 100%. | 723 // Width given to |zoom_label_|. This is the width at 100%. |
| 715 int zoom_label_width_; | 724 int zoom_label_width_; |
| 716 | 725 |
| 717 DISALLOW_COPY_AND_ASSIGN(ZoomView); | 726 DISALLOW_COPY_AND_ASSIGN(ZoomView); |
| 718 }; | 727 }; |
| 719 | 728 |
| 720 // WrenchMenu ------------------------------------------------------------------ | 729 // WrenchMenu ------------------------------------------------------------------ |
| 721 | 730 |
| 722 WrenchMenu::WrenchMenu(Browser* browser) | 731 WrenchMenu::WrenchMenu(Browser* browser) |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 bookmark_menu_delegate_.reset( | 1093 bookmark_menu_delegate_.reset( |
| 1085 new BookmarkMenuDelegate(browser_, | 1094 new BookmarkMenuDelegate(browser_, |
| 1086 NULL, | 1095 NULL, |
| 1087 parent, | 1096 parent, |
| 1088 first_bookmark_command_id_)); | 1097 first_bookmark_command_id_)); |
| 1089 bookmark_menu_delegate_->Init( | 1098 bookmark_menu_delegate_->Init( |
| 1090 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1099 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 1091 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1100 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1092 bookmark_utils::LAUNCH_WRENCH_MENU); | 1101 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 1093 } | 1102 } |
| OLD | NEW |