| 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" |
| 15 #include "ui/aura_shell/shell.h" | 16 #include "ui/aura_shell/shell.h" |
| 16 #include "ui/aura_shell/shell_delegate.h" | 17 #include "ui/aura_shell/shell_delegate.h" |
| 17 #include "ui/base/animation/animation.h" | 18 #include "ui/base/animation/animation.h" |
| 18 #include "ui/base/animation/throb_animation.h" | 19 #include "ui/base/animation/throb_animation.h" |
| 19 #include "ui/base/models/simple_menu_model.h" | 20 #include "ui/base/models/simple_menu_model.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/compositor/layer.h" | 23 #include "ui/gfx/compositor/layer.h" |
| 22 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 23 #include "ui/views/animation/bounds_animator.h" | 25 #include "ui/views/animation/bounds_animator.h" |
| 24 #include "ui/views/controls/button/image_button.h" | 26 #include "ui/views/controls/button/image_button.h" |
| 25 #include "ui/views/controls/menu/menu_model_adapter.h" | 27 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 26 #include "ui/views/controls/menu/menu_runner.h" | 28 #include "ui/views/controls/menu/menu_runner.h" |
| 29 #include "ui/views/painter.h" |
| 27 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 28 | 31 |
| 29 using ui::Animation; | 32 using ui::Animation; |
| 30 using views::View; | 33 using views::View; |
| 31 | 34 |
| 32 namespace aura_shell { | 35 namespace aura_shell { |
| 33 namespace internal { | 36 namespace internal { |
| 34 | 37 |
| 35 // Padding between each view. | 38 // Padding between each view. |
| 36 static const int kHorizontalPadding = 12; | 39 static const int kHorizontalPadding = 12; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 view_->layer()->SetOpacity(1.0f); | 121 view_->layer()->SetOpacity(1.0f); |
| 119 view_->layer()->ScheduleDraw(); | 122 view_->layer()->ScheduleDraw(); |
| 120 } | 123 } |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 views::View* view_; | 126 views::View* view_; |
| 124 | 127 |
| 125 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); | 128 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); |
| 126 }; | 129 }; |
| 127 | 130 |
| 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 |
| 128 } // namespace | 150 } // namespace |
| 129 | 151 |
| 130 // AnimationDelegate used when inserting a new item. This steadily decreased the | 152 // AnimationDelegate used when inserting a new item. This steadily decreased the |
| 131 // opacity of the layer as the animation progress. | 153 // opacity of the layer as the animation progress. |
| 132 class LauncherView::FadeOutAnimationDelegate : | 154 class LauncherView::FadeOutAnimationDelegate : |
| 133 public views::BoundsAnimator::OwnedAnimationDelegate { | 155 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 134 public: | 156 public: |
| 135 FadeOutAnimationDelegate(LauncherView* host, views::View* view) | 157 FadeOutAnimationDelegate(LauncherView* host, views::View* view) |
| 136 : launcher_view_(host), | 158 : launcher_view_(host), |
| 137 view_(view) {} | 159 view_(view) {} |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 start_drag_index_(-1) { | 217 start_drag_index_(-1) { |
| 196 DCHECK(model_); | 218 DCHECK(model_); |
| 197 bounds_animator_.reset(new views::BoundsAnimator(this)); | 219 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 198 } | 220 } |
| 199 | 221 |
| 200 LauncherView::~LauncherView() { | 222 LauncherView::~LauncherView() { |
| 201 model_->RemoveObserver(this); | 223 model_->RemoveObserver(this); |
| 202 } | 224 } |
| 203 | 225 |
| 204 void LauncherView::Init() { | 226 void LauncherView::Init() { |
| 227 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 205 model_->AddObserver(this); | 228 model_->AddObserver(this); |
| 206 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 229 |
| 230 set_background( |
| 231 views::Background::CreateBackgroundPainter(true, new ShelfPainter())); |
| 232 |
| 207 new_browser_button_ = new views::ImageButton(this); | 233 new_browser_button_ = new views::ImageButton(this); |
| 208 int new_browser_button_image_id = | 234 int new_browser_button_image_id = |
| 209 Shell::GetInstance()->delegate()->GetResourceIDForNewBrowserWindow(); | 235 Shell::GetInstance()->delegate()->GetResourceIDForNewBrowserWindow(); |
| 210 new_browser_button_->SetImage( | 236 new_browser_button_->SetImage( |
| 211 views::CustomButton::BS_NORMAL, | 237 views::CustomButton::BS_NORMAL, |
| 212 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap()); | 238 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap()); |
| 213 ConfigureChildView(new_browser_button_); | 239 ConfigureChildView(new_browser_button_); |
| 214 AddChildView(new_browser_button_); | 240 AddChildView(new_browser_button_); |
| 215 | 241 |
| 216 const LauncherItems& items(model_->items()); | 242 const LauncherItems& items(model_->items()); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } else { | 601 } else { |
| 576 int view_index = view_model_->GetIndexOfView(sender); | 602 int view_index = view_model_->GetIndexOfView(sender); |
| 577 // May be -1 while in the process of animating closed. | 603 // May be -1 while in the process of animating closed. |
| 578 if (view_index != -1) | 604 if (view_index != -1) |
| 579 delegate->LauncherItemClicked(model_->items()[view_index]); | 605 delegate->LauncherItemClicked(model_->items()[view_index]); |
| 580 } | 606 } |
| 581 } | 607 } |
| 582 | 608 |
| 583 } // namespace internal | 609 } // namespace internal |
| 584 } // namespace aura_shell | 610 } // namespace aura_shell |
| OLD | NEW |