| 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" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 activated_command_id_ = command_id; | 75 activated_command_id_ = command_id; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 // ID of the command passed to ExecuteCommand. | 79 // ID of the command passed to ExecuteCommand. |
| 80 int activated_command_id_; | 80 int activated_command_id_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl); | 82 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl); |
| 83 }; | 83 }; |
| 84 | 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 | |
| 127 // AnimationDelegate that deletes a view when done. This is used when a launcher | 85 // AnimationDelegate that deletes a view when done. This is used when a launcher |
| 128 // item is removed, which triggers a remove animation. When the animation is | 86 // item is removed, which triggers a remove animation. When the animation is |
| 129 // done we delete the view. | 87 // done we delete the view. |
| 130 class DeleteViewAnimationDelegate : | 88 class DeleteViewAnimationDelegate : |
| 131 public views::BoundsAnimator::OwnedAnimationDelegate { | 89 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 132 public: | 90 public: |
| 133 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {} | 91 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {} |
| 134 virtual ~DeleteViewAnimationDelegate() {} | 92 virtual ~DeleteViewAnimationDelegate() {} |
| 135 | 93 |
| 136 private: | 94 private: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 bounds_animator_.reset(new views::BoundsAnimator(this)); | 197 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 240 } | 198 } |
| 241 | 199 |
| 242 LauncherView::~LauncherView() { | 200 LauncherView::~LauncherView() { |
| 243 model_->RemoveObserver(this); | 201 model_->RemoveObserver(this); |
| 244 } | 202 } |
| 245 | 203 |
| 246 void LauncherView::Init() { | 204 void LauncherView::Init() { |
| 247 model_->AddObserver(this); | 205 model_->AddObserver(this); |
| 248 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 206 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 249 new_browser_button_ = new FadeButton(this); | 207 new_browser_button_ = new views::ImageButton(this); |
| 208 int new_browser_button_image_id = |
| 209 Shell::GetInstance()->delegate()->GetResourceIDForNewBrowserWindow(); |
| 250 new_browser_button_->SetImage( | 210 new_browser_button_->SetImage( |
| 251 views::CustomButton::BS_NORMAL, | 211 views::CustomButton::BS_NORMAL, |
| 252 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_CHROME).ToSkBitmap()); | 212 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap()); |
| 253 ConfigureChildView(new_browser_button_); | 213 ConfigureChildView(new_browser_button_); |
| 254 AddChildView(new_browser_button_); | 214 AddChildView(new_browser_button_); |
| 255 | 215 |
| 256 const LauncherItems& items(model_->items()); | 216 const LauncherItems& items(model_->items()); |
| 257 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 217 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| 258 views::View* child = CreateViewForItem(*i); | 218 views::View* child = CreateViewForItem(*i); |
| 259 child->SetPaintToLayer(true); | 219 child->SetPaintToLayer(true); |
| 260 view_model_->Add(child, static_cast<int>(i - items.begin())); | 220 view_model_->Add(child, static_cast<int>(i - items.begin())); |
| 261 AddChildView(child); | 221 AddChildView(child); |
| 262 } | 222 } |
| 263 | 223 |
| 264 show_apps_button_ = new FadeButton(this); | 224 show_apps_button_ = new views::ImageButton(this); |
| 265 show_apps_button_->SetImage( | 225 show_apps_button_->SetImage( |
| 266 views::CustomButton::BS_NORMAL, | 226 views::CustomButton::BS_NORMAL, |
| 267 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); | 227 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); |
| 228 show_apps_button_->SetImage( |
| 229 views::CustomButton::BS_HOT, |
| 230 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).ToSkBitmap()); |
| 231 show_apps_button_->SetImage( |
| 232 views::CustomButton::BS_PUSHED, |
| 233 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).ToSkBitmap()); |
| 268 ConfigureChildView(show_apps_button_); | 234 ConfigureChildView(show_apps_button_); |
| 269 AddChildView(show_apps_button_); | 235 AddChildView(show_apps_button_); |
| 270 | 236 |
| 271 overflow_button_ = new FadeButton(this); | 237 overflow_button_ = new views::ImageButton(this); |
| 272 // TODO: need image for this. | |
| 273 overflow_button_->SetImage( | 238 overflow_button_->SetImage( |
| 274 views::CustomButton::BS_NORMAL, | 239 views::CustomButton::BS_NORMAL, |
| 275 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); | 240 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); |
| 241 overflow_button_->SetImage( |
| 242 views::CustomButton::BS_HOT, |
| 243 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToSkBitmap()); |
| 244 overflow_button_->SetImage( |
| 245 views::CustomButton::BS_PUSHED, |
| 246 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToSkBitmap()); |
| 276 ConfigureChildView(overflow_button_); | 247 ConfigureChildView(overflow_button_); |
| 277 AddChildView(overflow_button_); | 248 AddChildView(overflow_button_); |
| 278 | 249 |
| 279 // We'll layout when our bounds change. | 250 // We'll layout when our bounds change. |
| 280 } | 251 } |
| 281 | 252 |
| 282 void LauncherView::LayoutToIdealBounds() { | 253 void LauncherView::LayoutToIdealBounds() { |
| 283 IdealBounds ideal_bounds; | 254 IdealBounds ideal_bounds; |
| 284 CalculateIdealBounds(&ideal_bounds); | 255 CalculateIdealBounds(&ideal_bounds); |
| 285 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); | 256 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 overflow_button_->SetVisible(show_overflow); | 300 overflow_button_->SetVisible(show_overflow); |
| 330 if (show_overflow) { | 301 if (show_overflow) { |
| 331 DCHECK_NE(0, view_model_->view_size()); | 302 DCHECK_NE(0, view_model_->view_size()); |
| 332 x = view_model_->ideal_bounds(last_visible_index).right() + | 303 x = view_model_->ideal_bounds(last_visible_index).right() + |
| 333 kHorizontalPadding; | 304 kHorizontalPadding; |
| 334 bounds->overflow_bounds.set_x(x); | 305 bounds->overflow_bounds.set_x(x); |
| 335 bounds->overflow_bounds.set_y( | 306 bounds->overflow_bounds.set_y( |
| 336 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); | 307 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); |
| 337 x = bounds->overflow_bounds.right() + kHorizontalPadding; | 308 x = bounds->overflow_bounds.right() + kHorizontalPadding; |
| 338 } | 309 } |
| 339 // TODO(sky): -8 is a hack, remove when we get better images. | 310 // TODO(sky): -6 is a hack, remove when we get better images. |
| 340 bounds->show_apps_bounds.set_x(x - 8); | 311 bounds->show_apps_bounds.set_x(x - 6); |
| 341 bounds->show_apps_bounds.set_y( | 312 bounds->show_apps_bounds.set_y( |
| 342 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); | 313 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); |
| 343 } | 314 } |
| 344 | 315 |
| 345 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 316 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
| 346 int index = view_model_->view_size() - 1; | 317 int index = view_model_->view_size() - 1; |
| 347 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) | 318 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) |
| 348 index--; | 319 index--; |
| 349 return index; | 320 return index; |
| 350 } | 321 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 } else { | 575 } else { |
| 605 int view_index = view_model_->GetIndexOfView(sender); | 576 int view_index = view_model_->GetIndexOfView(sender); |
| 606 // May be -1 while in the process of animating closed. | 577 // May be -1 while in the process of animating closed. |
| 607 if (view_index != -1) | 578 if (view_index != -1) |
| 608 delegate->LauncherItemClicked(model_->items()[view_index]); | 579 delegate->LauncherItemClicked(model_->items()[view_index]); |
| 609 } | 580 } |
| 610 } | 581 } |
| 611 | 582 |
| 612 } // namespace internal | 583 } // namespace internal |
| 613 } // namespace aura_shell | 584 } // namespace aura_shell |
| OLD | NEW |