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/launcher_view.h" | 5 #include "ui/aura_shell/launcher/launcher_view.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura_shell/launcher/app_launcher_button.h" | 10 #include "ui/aura_shell/launcher/app_launcher_button.h" |
11 #include "ui/aura_shell/launcher/launcher_model.h" | 11 #include "ui/aura_shell/launcher/launcher_model.h" |
12 #include "ui/aura_shell/launcher/tabbed_launcher_button.h" | 12 #include "ui/aura_shell/launcher/tabbed_launcher_button.h" |
13 #include "ui/aura_shell/launcher/view_model.h" | 13 #include "ui/aura_shell/launcher/view_model.h" |
14 #include "ui/aura_shell/launcher/view_model_utils.h" | 14 #include "ui/aura_shell/launcher/view_model_utils.h" |
15 #include "ui/aura_shell/shelf_layout_manager.h" | |
16 #include "ui/aura_shell/shell.h" | 15 #include "ui/aura_shell/shell.h" |
17 #include "ui/aura_shell/shell_delegate.h" | 16 #include "ui/aura_shell/shell_delegate.h" |
18 #include "ui/base/animation/animation.h" | 17 #include "ui/base/animation/animation.h" |
19 #include "ui/base/animation/throb_animation.h" | 18 #include "ui/base/animation/throb_animation.h" |
20 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/canvas.h" | |
23 #include "ui/gfx/compositor/layer.h" | 21 #include "ui/gfx/compositor/layer.h" |
24 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
25 #include "ui/views/animation/bounds_animator.h" | 23 #include "ui/views/animation/bounds_animator.h" |
26 #include "ui/views/controls/button/image_button.h" | 24 #include "ui/views/controls/button/image_button.h" |
27 #include "ui/views/controls/menu/menu_model_adapter.h" | 25 #include "ui/views/controls/menu/menu_model_adapter.h" |
28 #include "ui/views/controls/menu/menu_runner.h" | 26 #include "ui/views/controls/menu/menu_runner.h" |
29 #include "ui/views/painter.h" | |
30 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
31 | 28 |
32 using ui::Animation; | 29 using ui::Animation; |
33 using views::View; | 30 using views::View; |
34 | 31 |
35 namespace aura_shell { | 32 namespace aura_shell { |
36 namespace internal { | 33 namespace internal { |
37 | 34 |
38 // Padding between each view. | 35 // Padding between each view. |
39 static const int kHorizontalPadding = 12; | 36 static const int kHorizontalPadding = 12; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 activated_command_id_ = command_id; | 75 activated_command_id_ = command_id; |
79 } | 76 } |
80 | 77 |
81 private: | 78 private: |
82 // ID of the command passed to ExecuteCommand. | 79 // ID of the command passed to ExecuteCommand. |
83 int activated_command_id_; | 80 int activated_command_id_; |
84 | 81 |
85 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl); | 82 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl); |
86 }; | 83 }; |
87 | 84 |
| 85 // ImageButton subclass that animates transition changes using the opacity of |
| 86 // the layer. |
| 87 class FadeButton : public views::ImageButton { |
| 88 public: |
| 89 explicit FadeButton(views::ButtonListener* listener) |
| 90 : ImageButton(listener) { |
| 91 SetPaintToLayer(true); |
| 92 layer()->SetFillsBoundsOpaquely(false); |
| 93 layer()->SetOpacity(kDimmedButtonOpacity); |
| 94 } |
| 95 |
| 96 protected: |
| 97 // ImageButton overrides: |
| 98 virtual SkBitmap GetImageToPaint() OVERRIDE { |
| 99 // ImageButton::GetImageToPaint returns an alpha blended image based on |
| 100 // hover_animation_. FadeButton uses hover_animation to change the opacity |
| 101 // of the layer, so this can be overriden to return the normal image always. |
| 102 return images_[BS_NORMAL]; |
| 103 } |
| 104 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { |
| 105 layer()->SetOpacity(kDimmedButtonOpacity + (1.0f - kDimmedButtonOpacity) * |
| 106 animation->GetCurrentValue()); |
| 107 layer()->ScheduleDraw(); |
| 108 } |
| 109 virtual void StateChanged() OVERRIDE { |
| 110 if (!hover_animation_->is_animating()) { |
| 111 float opacity = state_ == BS_NORMAL ? kDimmedButtonOpacity : 1.0f; |
| 112 if (layer()->opacity() != opacity) { |
| 113 layer()->SetOpacity(opacity); |
| 114 layer()->ScheduleDraw(); |
| 115 } |
| 116 } |
| 117 } |
| 118 virtual void SchedulePaint() OVERRIDE { |
| 119 // All changes we care about trigger a draw on the layer, so this can be |
| 120 // overriden to do nothing. |
| 121 } |
| 122 |
| 123 private: |
| 124 DISALLOW_COPY_AND_ASSIGN(FadeButton); |
| 125 }; |
| 126 |
88 // AnimationDelegate that deletes a view when done. This is used when a launcher | 127 // AnimationDelegate that deletes a view when done. This is used when a launcher |
89 // item is removed, which triggers a remove animation. When the animation is | 128 // item is removed, which triggers a remove animation. When the animation is |
90 // done we delete the view. | 129 // done we delete the view. |
91 class DeleteViewAnimationDelegate : | 130 class DeleteViewAnimationDelegate : |
92 public views::BoundsAnimator::OwnedAnimationDelegate { | 131 public views::BoundsAnimator::OwnedAnimationDelegate { |
93 public: | 132 public: |
94 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {} | 133 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {} |
95 virtual ~DeleteViewAnimationDelegate() {} | 134 virtual ~DeleteViewAnimationDelegate() {} |
96 | 135 |
97 private: | 136 private: |
(...skipping 23 matching lines...) Expand all Loading... |
121 view_->layer()->SetOpacity(1.0f); | 160 view_->layer()->SetOpacity(1.0f); |
122 view_->layer()->ScheduleDraw(); | 161 view_->layer()->ScheduleDraw(); |
123 } | 162 } |
124 | 163 |
125 private: | 164 private: |
126 views::View* view_; | 165 views::View* view_; |
127 | 166 |
128 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); | 167 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); |
129 }; | 168 }; |
130 | 169 |
131 // Used to draw the background of the shelf. | |
132 class ShelfPainter : public views::Painter { | |
133 public: | |
134 ShelfPainter() { | |
135 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
136 image_ = *rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToSkBitmap(); | |
137 } | |
138 | |
139 virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE { | |
140 canvas->TileImageInt(image_, 0, 0, w, h); | |
141 } | |
142 | |
143 private: | |
144 SkBitmap image_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(ShelfPainter); | |
147 }; | |
148 | |
149 | |
150 } // namespace | 170 } // namespace |
151 | 171 |
152 // AnimationDelegate used when inserting a new item. This steadily decreased the | 172 // AnimationDelegate used when inserting a new item. This steadily decreased the |
153 // opacity of the layer as the animation progress. | 173 // opacity of the layer as the animation progress. |
154 class LauncherView::FadeOutAnimationDelegate : | 174 class LauncherView::FadeOutAnimationDelegate : |
155 public views::BoundsAnimator::OwnedAnimationDelegate { | 175 public views::BoundsAnimator::OwnedAnimationDelegate { |
156 public: | 176 public: |
157 FadeOutAnimationDelegate(LauncherView* host, views::View* view) | 177 FadeOutAnimationDelegate(LauncherView* host, views::View* view) |
158 : launcher_view_(host), | 178 : launcher_view_(host), |
159 view_(view) {} | 179 view_(view) {} |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 start_drag_index_(-1) { | 237 start_drag_index_(-1) { |
218 DCHECK(model_); | 238 DCHECK(model_); |
219 bounds_animator_.reset(new views::BoundsAnimator(this)); | 239 bounds_animator_.reset(new views::BoundsAnimator(this)); |
220 } | 240 } |
221 | 241 |
222 LauncherView::~LauncherView() { | 242 LauncherView::~LauncherView() { |
223 model_->RemoveObserver(this); | 243 model_->RemoveObserver(this); |
224 } | 244 } |
225 | 245 |
226 void LauncherView::Init() { | 246 void LauncherView::Init() { |
| 247 model_->AddObserver(this); |
227 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 248 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
228 model_->AddObserver(this); | 249 new_browser_button_ = new FadeButton(this); |
229 | |
230 set_background( | |
231 views::Background::CreateBackgroundPainter(true, new ShelfPainter())); | |
232 | |
233 new_browser_button_ = new views::ImageButton(this); | |
234 int new_browser_button_image_id = | |
235 Shell::GetInstance()->delegate()->GetResourceIDForNewBrowserWindow(); | |
236 new_browser_button_->SetImage( | 250 new_browser_button_->SetImage( |
237 views::CustomButton::BS_NORMAL, | 251 views::CustomButton::BS_NORMAL, |
238 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap()); | 252 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_CHROME).ToSkBitmap()); |
239 ConfigureChildView(new_browser_button_); | 253 ConfigureChildView(new_browser_button_); |
240 AddChildView(new_browser_button_); | 254 AddChildView(new_browser_button_); |
241 | 255 |
242 const LauncherItems& items(model_->items()); | 256 const LauncherItems& items(model_->items()); |
243 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 257 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
244 views::View* child = CreateViewForItem(*i); | 258 views::View* child = CreateViewForItem(*i); |
245 child->SetPaintToLayer(true); | 259 child->SetPaintToLayer(true); |
246 view_model_->Add(child, static_cast<int>(i - items.begin())); | 260 view_model_->Add(child, static_cast<int>(i - items.begin())); |
247 AddChildView(child); | 261 AddChildView(child); |
248 } | 262 } |
249 | 263 |
250 show_apps_button_ = new views::ImageButton(this); | 264 show_apps_button_ = new FadeButton(this); |
251 show_apps_button_->SetImage( | 265 show_apps_button_->SetImage( |
252 views::CustomButton::BS_NORMAL, | 266 views::CustomButton::BS_NORMAL, |
253 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); | 267 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); |
254 show_apps_button_->SetImage( | |
255 views::CustomButton::BS_HOT, | |
256 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).ToSkBitmap()); | |
257 show_apps_button_->SetImage( | |
258 views::CustomButton::BS_PUSHED, | |
259 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).ToSkBitmap()); | |
260 ConfigureChildView(show_apps_button_); | 268 ConfigureChildView(show_apps_button_); |
261 AddChildView(show_apps_button_); | 269 AddChildView(show_apps_button_); |
262 | 270 |
263 overflow_button_ = new views::ImageButton(this); | 271 overflow_button_ = new FadeButton(this); |
| 272 // TODO: need image for this. |
264 overflow_button_->SetImage( | 273 overflow_button_->SetImage( |
265 views::CustomButton::BS_NORMAL, | 274 views::CustomButton::BS_NORMAL, |
266 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); | 275 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); |
267 overflow_button_->SetImage( | |
268 views::CustomButton::BS_HOT, | |
269 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToSkBitmap()); | |
270 overflow_button_->SetImage( | |
271 views::CustomButton::BS_PUSHED, | |
272 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToSkBitmap()); | |
273 ConfigureChildView(overflow_button_); | 276 ConfigureChildView(overflow_button_); |
274 AddChildView(overflow_button_); | 277 AddChildView(overflow_button_); |
275 | 278 |
276 // We'll layout when our bounds change. | 279 // We'll layout when our bounds change. |
277 } | 280 } |
278 | 281 |
279 void LauncherView::LayoutToIdealBounds() { | 282 void LauncherView::LayoutToIdealBounds() { |
280 IdealBounds ideal_bounds; | 283 IdealBounds ideal_bounds; |
281 CalculateIdealBounds(&ideal_bounds); | 284 CalculateIdealBounds(&ideal_bounds); |
282 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); | 285 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 overflow_button_->SetVisible(show_overflow); | 329 overflow_button_->SetVisible(show_overflow); |
327 if (show_overflow) { | 330 if (show_overflow) { |
328 DCHECK_NE(0, view_model_->view_size()); | 331 DCHECK_NE(0, view_model_->view_size()); |
329 x = view_model_->ideal_bounds(last_visible_index).right() + | 332 x = view_model_->ideal_bounds(last_visible_index).right() + |
330 kHorizontalPadding; | 333 kHorizontalPadding; |
331 bounds->overflow_bounds.set_x(x); | 334 bounds->overflow_bounds.set_x(x); |
332 bounds->overflow_bounds.set_y( | 335 bounds->overflow_bounds.set_y( |
333 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); | 336 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); |
334 x = bounds->overflow_bounds.right() + kHorizontalPadding; | 337 x = bounds->overflow_bounds.right() + kHorizontalPadding; |
335 } | 338 } |
336 // TODO(sky): -6 is a hack, remove when we get better images. | 339 // TODO(sky): -8 is a hack, remove when we get better images. |
337 bounds->show_apps_bounds.set_x(x - 6); | 340 bounds->show_apps_bounds.set_x(x - 8); |
338 bounds->show_apps_bounds.set_y( | 341 bounds->show_apps_bounds.set_y( |
339 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); | 342 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); |
340 } | 343 } |
341 | 344 |
342 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 345 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
343 int index = view_model_->view_size() - 1; | 346 int index = view_model_->view_size() - 1; |
344 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) | 347 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) |
345 index--; | 348 index--; |
346 return index; | 349 return index; |
347 } | 350 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 } else { | 604 } else { |
602 int view_index = view_model_->GetIndexOfView(sender); | 605 int view_index = view_model_->GetIndexOfView(sender); |
603 // May be -1 while in the process of animating closed. | 606 // May be -1 while in the process of animating closed. |
604 if (view_index != -1) | 607 if (view_index != -1) |
605 delegate->LauncherItemClicked(model_->items()[view_index]); | 608 delegate->LauncherItemClicked(model_->items()[view_index]); |
606 } | 609 } |
607 } | 610 } |
608 | 611 |
609 } // namespace internal | 612 } // namespace internal |
610 } // namespace aura_shell | 613 } // namespace aura_shell |
OLD | NEW |