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