OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/launcher/tabbed_launcher_button.h" | 5 #include "ui/aura_shell/launcher/tabbed_launcher_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
10 #include "ui/aura_shell/launcher/launcher_button_host.h" | 10 #include "ui/aura_shell/launcher/launcher_button_host.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 // Insets used in painting the background if it's rendered bigger than the size | 26 // Insets used in painting the background if it's rendered bigger than the size |
27 // of the background image. See ImagePainter::CreateImagePainter for how these | 27 // of the background image. See ImagePainter::CreateImagePainter for how these |
28 // are interpreted. | 28 // are interpreted. |
29 const int kBgTopInset = 12; | 29 const int kBgTopInset = 12; |
30 const int kBgLeftInset = 30; | 30 const int kBgLeftInset = 30; |
31 const int kBgBottomInset = 12; | 31 const int kBgBottomInset = 12; |
32 const int kBgRightInset = 8; | 32 const int kBgRightInset = 8; |
33 | 33 |
34 // static | 34 // static |
35 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_1_ = NULL; | 35 SkBitmap* TabbedLauncherButton::bg_image_1_ = NULL; |
36 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_2_ = NULL; | 36 SkBitmap* TabbedLauncherButton::bg_image_2_ = NULL; |
37 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_3_ = NULL; | 37 SkBitmap* TabbedLauncherButton::bg_image_3_ = NULL; |
38 | 38 |
39 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener, | 39 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener, |
40 LauncherButtonHost* host) | 40 LauncherButtonHost* host) |
41 : views::ImageButton(listener), | 41 : views::CustomButton(listener), |
42 host_(host) { | 42 host_(host) { |
43 if (!bg_image_1_) { | 43 if (!bg_image_1_) { |
44 bg_image_1_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_1, | 44 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
45 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_PUSHED, | 45 bg_image_1_ = new SkBitmap( |
46 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_HOT); | 46 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_1).ToSkBitmap()); |
47 bg_image_2_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_2, | 47 bg_image_2_ = new SkBitmap( |
48 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_PUSHED, | 48 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_2).ToSkBitmap()); |
49 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_HOT); | 49 bg_image_3_ = new SkBitmap( |
50 bg_image_3_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_3, | 50 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_3).ToSkBitmap()); |
51 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_PUSHED, | |
52 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_HOT); | |
53 } | 51 } |
54 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
55 views::ImageButton::ALIGN_MIDDLE); | |
56 } | 52 } |
57 | 53 |
58 TabbedLauncherButton::~TabbedLauncherButton() { | 54 TabbedLauncherButton::~TabbedLauncherButton() { |
59 } | 55 } |
60 | 56 |
61 void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) { | 57 void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) { |
62 images_ = images; | 58 images_ = images; |
63 ImageSet* set; | 59 } |
64 if (images_.size() <= 1) | 60 |
65 set = bg_image_1_; | 61 gfx::Size TabbedLauncherButton::GetPreferredSize() { |
66 else if (images_.size() == 2) | 62 return gfx::Size(bg_image_1_->width(), bg_image_1_->height()); |
67 set = bg_image_2_; | |
68 else | |
69 set = bg_image_3_; | |
70 SetImage(BS_NORMAL, set->normal_image); | |
71 SetImage(BS_HOT, set->hot_image); | |
72 SetImage(BS_PUSHED, set->pushed_image); | |
73 } | 63 } |
74 | 64 |
75 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) { | 65 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) { |
76 ImageButton::OnPaint(canvas); | 66 SkBitmap* bg_image = NULL; |
| 67 if (images_.size() <= 1) |
| 68 bg_image = bg_image_1_; |
| 69 else if (images_.size() == 2) |
| 70 bg_image = bg_image_2_; |
| 71 else |
| 72 bg_image = bg_image_3_; |
| 73 canvas->DrawBitmapInt(*bg_image, 0, 0); |
77 | 74 |
78 if (images_.empty()) | 75 if (images_.empty()) |
79 return; | 76 return; |
80 | 77 |
81 // Only show the first icon. | 78 // Only show the first icon. |
82 // TODO(sky): if we settle on just 1 icon, then we should simplify surrounding | 79 // TODO(sky): if we settle on just 1 icon, then we should simplify surrounding |
83 // code (don't use a vector of images). | 80 // code (don't use a vector of images). |
84 int x = (width() - images_[0].image.width()) / 2; | 81 int x = (width() - images_[0].image.width()) / 2; |
85 int y = (height() - images_[0].image.height()) / 2 + 1; | 82 int y = (height() - images_[0].image.height()) / 2; |
86 canvas->DrawBitmapInt(images_[0].image, x, y); | 83 canvas->DrawBitmapInt(images_[0].image, x, y); |
87 } | 84 } |
88 | 85 |
89 bool TabbedLauncherButton::OnMousePressed(const views::MouseEvent& event) { | 86 bool TabbedLauncherButton::OnMousePressed(const views::MouseEvent& event) { |
90 ImageButton::OnMousePressed(event); | 87 CustomButton::OnMousePressed(event); |
91 host_->MousePressedOnButton(this, event); | 88 host_->MousePressedOnButton(this, event); |
92 return true; | 89 return true; |
93 } | 90 } |
94 | 91 |
95 void TabbedLauncherButton::OnMouseReleased(const views::MouseEvent& event) { | 92 void TabbedLauncherButton::OnMouseReleased(const views::MouseEvent& event) { |
96 host_->MouseReleasedOnButton(this, false); | 93 host_->MouseReleasedOnButton(this, false); |
97 ImageButton::OnMouseReleased(event); | 94 CustomButton::OnMouseReleased(event); |
98 } | 95 } |
99 | 96 |
100 void TabbedLauncherButton::OnMouseCaptureLost() { | 97 void TabbedLauncherButton::OnMouseCaptureLost() { |
101 host_->MouseReleasedOnButton(this, true); | 98 host_->MouseReleasedOnButton(this, true); |
102 ImageButton::OnMouseCaptureLost(); | 99 CustomButton::OnMouseCaptureLost(); |
103 } | 100 } |
104 | 101 |
105 bool TabbedLauncherButton::OnMouseDragged(const views::MouseEvent& event) { | 102 bool TabbedLauncherButton::OnMouseDragged(const views::MouseEvent& event) { |
106 ImageButton::OnMouseDragged(event); | 103 CustomButton::OnMouseDragged(event); |
107 host_->MouseDraggedOnButton(this, event); | 104 host_->MouseDraggedOnButton(this, event); |
108 return true; | 105 return true; |
109 } | 106 } |
110 | 107 |
111 // static | |
112 TabbedLauncherButton::ImageSet* TabbedLauncherButton::CreateImageSet( | |
113 int normal_id, | |
114 int pushed_id, | |
115 int hot_id) { | |
116 ImageSet* set = new ImageSet; | |
117 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
118 set->normal_image = new SkBitmap(*rb.GetImageNamed(normal_id).ToSkBitmap()); | |
119 set->pushed_image = new SkBitmap(*rb.GetImageNamed(pushed_id).ToSkBitmap()); | |
120 set->hot_image = new SkBitmap(*rb.GetImageNamed(hot_id).ToSkBitmap()); | |
121 return set; | |
122 } | |
123 | |
124 } // namespace internal | 108 } // namespace internal |
125 } // namespace aura_shell | 109 } // namespace aura_shell |
OLD | NEW |