Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: ash/launcher/launcher.cc

Issue 11644033: Rotated Images (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/launcher/launcher.h ('k') | ash/launcher/launcher_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/launcher/launcher.h" 5 #include "ash/launcher/launcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "ash/focus_cycler.h" 10 #include "ash/focus_cycler.h"
11 #include "ash/launcher/launcher_delegate.h" 11 #include "ash/launcher/launcher_delegate.h"
12 #include "ash/launcher/launcher_model.h" 12 #include "ash/launcher/launcher_model.h"
13 #include "ash/launcher/launcher_navigator.h" 13 #include "ash/launcher/launcher_navigator.h"
14 #include "ash/launcher/launcher_view.h" 14 #include "ash/launcher/launcher_view.h"
15 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell_delegate.h" 17 #include "ash/shell_delegate.h"
18 #include "ash/shell_window_ids.h" 18 #include "ash/shell_window_ids.h"
19 #include "ash/wm/property_util.h"
19 #include "ash/wm/shelf_layout_manager.h" 20 #include "ash/wm/shelf_layout_manager.h"
20 #include "ash/wm/window_properties.h" 21 #include "ash/wm/window_properties.h"
21 #include "grit/ash_resources.h" 22 #include "grit/ash_resources.h"
22 #include "ui/aura/client/activation_client.h" 23 #include "ui/aura/client/activation_client.h"
23 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
24 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
25 #include "ui/aura/window_observer.h" 26 #include "ui/aura/window_observer.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/compositor/layer.h" 28 #include "ui/compositor/layer.h"
28 #include "ui/gfx/canvas.h" 29 #include "ui/gfx/canvas.h"
29 #include "ui/gfx/image/image.h" 30 #include "ui/gfx/image/image.h"
31 #include "ui/gfx/image/image_skia_operations.h"
32 #include "ui/gfx/skbitmap_operations.h"
30 #include "ui/views/accessible_pane_view.h" 33 #include "ui/views/accessible_pane_view.h"
31 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
32 #include "ui/views/widget/widget_delegate.h" 35 #include "ui/views/widget/widget_delegate.h"
33 36
34 namespace { 37 namespace {
35 // Size of black border at bottom (or side) of launcher. 38 // Size of black border at bottom (or side) of launcher.
36 const int kNumBlackPixels = 3; 39 const int kNumBlackPixels = 3;
37 // Alpha to paint dimming image with. 40 // Alpha to paint dimming image with.
38 const int kDimAlpha = 96; 41 const int kDimAlpha = 96;
39 } 42 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Launcher* launcher_; 89 Launcher* launcher_;
87 internal::FocusCycler* focus_cycler_; 90 internal::FocusCycler* focus_cycler_;
88 int alpha_; 91 int alpha_;
89 92
90 DISALLOW_COPY_AND_ASSIGN(DelegateView); 93 DISALLOW_COPY_AND_ASSIGN(DelegateView);
91 }; 94 };
92 95
93 // Class used to slightly dim shelf items when maximized and visible. It also 96 // Class used to slightly dim shelf items when maximized and visible. It also
94 // makes sure the widget changes size to always be of the same size as the 97 // makes sure the widget changes size to always be of the same size as the
95 // shelf. 98 // shelf.
96 class DimmerView : public views::WidgetDelegateView, 99 class Launcher::DimmerView : public views::WidgetDelegateView,
97 public aura::WindowObserver { 100 public aura::WindowObserver {
98 public: 101 public:
99 explicit DimmerView(views::Widget* launcher) 102 explicit DimmerView(Launcher* launcher)
100 : launcher_(launcher) { 103 : launcher_(launcher) {
101 launcher_->GetNativeWindow()->AddObserver(this); 104 launcher_->widget()->GetNativeWindow()->AddObserver(this);
102 } 105 }
103 106
104 ~DimmerView() { 107 ~DimmerView() {
105 if (launcher_) 108 if (launcher_)
106 launcher_->GetNativeWindow()->RemoveObserver(this); 109 launcher_->widget()->GetNativeWindow()->RemoveObserver(this);
107 } 110 }
108 111
109 private: 112 private:
110 // views::View overrides: 113 // views::View overrides:
111 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { 114 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE {
112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 115 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
113 const gfx::ImageSkia* launcher_background = rb.GetImageSkiaNamed( 116 gfx::ImageSkia background_image =
114 internal::ShelfLayoutManager::ForLauncher( 117 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_DIMMING);
115 launcher_->GetNativeView())-> 118 if (SHELF_ALIGNMENT_BOTTOM != launcher_->alignment_)
116 SelectValueForShelfAlignment(IDR_AURA_LAUNCHER_DIMMING_BOTTOM, 119 background_image = gfx::ImageSkiaOperations::CreateRotatedImage(
117 IDR_AURA_LAUNCHER_DIMMING_LEFT, 120 background_image,
118 IDR_AURA_LAUNCHER_DIMMING_RIGHT)); 121 (SHELF_ALIGNMENT_LEFT == launcher_->alignment_ ?
122 SkBitmapOperations::ROTATION_90_CW :
123 SkBitmapOperations::ROTATION_270_CW));
124
119 SkPaint paint; 125 SkPaint paint;
120 paint.setAlpha(kDimAlpha); 126 paint.setAlpha(kDimAlpha);
121 canvas->DrawImageInt( 127 canvas->DrawImageInt(
122 *launcher_background, 128 background_image,
123 0, 0, launcher_background->width(), launcher_background->height(), 129 0, 0, background_image.width(), background_image.height(),
124 0, 0, width(), height(), 130 0, 0, width(), height(),
125 false, 131 false,
126 paint); 132 paint);
127 } 133 }
128 134
129 // aura::WindowObserver overrides: 135 // aura::WindowObserver overrides:
130 virtual void OnWindowBoundsChanged(aura::Window* window, 136 virtual void OnWindowBoundsChanged(aura::Window* window,
131 const gfx::Rect& old_bounds, 137 const gfx::Rect& old_bounds,
132 const gfx::Rect& new_bounds) OVERRIDE { 138 const gfx::Rect& new_bounds) OVERRIDE {
133 CHECK_EQ(window, launcher_->GetNativeWindow()); 139 CHECK_EQ(window, launcher_->widget()->GetNativeWindow());
134 GetWidget()->GetNativeWindow()->SetBounds(window->bounds()); 140 GetWidget()->GetNativeWindow()->SetBounds(window->bounds());
135 } 141 }
136 142
137 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 143 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
138 CHECK_EQ(window, launcher_->GetNativeWindow()); 144 CHECK_EQ(window, launcher_->widget()->GetNativeWindow());
139 launcher_->GetNativeWindow()->RemoveObserver(this); 145 launcher_->widget()->GetNativeWindow()->RemoveObserver(this);
140 launcher_ = NULL; 146 launcher_ = NULL;
141 } 147 }
142 148
143 views::Widget* launcher_; 149 Launcher* launcher_;
144 DISALLOW_COPY_AND_ASSIGN(DimmerView); 150 DISALLOW_COPY_AND_ASSIGN(DimmerView);
145 }; 151 };
146 152
147 Launcher::DelegateView::DelegateView(Launcher* launcher) 153 Launcher::DelegateView::DelegateView(Launcher* launcher)
148 : launcher_(launcher), 154 : launcher_(launcher),
149 focus_cycler_(NULL), 155 focus_cycler_(NULL),
150 alpha_(0) { 156 alpha_(0) {
151 } 157 }
152 158
153 Launcher::DelegateView::~DelegateView() { 159 Launcher::DelegateView::~DelegateView() {
(...skipping 11 matching lines...) Expand all
165 if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) { 171 if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) {
166 int w = std::max(0, width() - launcher_->status_size_.width()); 172 int w = std::max(0, width() - launcher_->status_size_.width());
167 launcher_view->SetBounds(0, 0, w, height()); 173 launcher_view->SetBounds(0, 0, w, height());
168 } else { 174 } else {
169 int h = std::max(0, height() - launcher_->status_size_.height()); 175 int h = std::max(0, height() - launcher_->status_size_.height());
170 launcher_view->SetBounds(0, 0, width(), h); 176 launcher_view->SetBounds(0, 0, width(), h);
171 } 177 }
172 } 178 }
173 179
174 void Launcher::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 180 void Launcher::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
175 if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) { 181 ash::internal::ShelfLayoutManager* shelf = ash::GetRootWindowController(
176 SkPaint paint; 182 GetWidget()->GetNativeView()->GetRootWindow())->shelf();
177 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 183 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
178 const gfx::ImageSkia* launcher_background = rb.GetImageSkiaNamed( 184 gfx::ImageSkia launcher_background =
179 internal::ShelfLayoutManager::ForLauncher( 185 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND);
180 launcher_->widget()->GetNativeView())-> 186 if (launcher_->alignment_ != SHELF_ALIGNMENT_BOTTOM)
181 SelectValueForShelfAlignment(IDR_AURA_LAUNCHER_BACKGROUND_BOTTOM, 187 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage(
182 IDR_AURA_LAUNCHER_BACKGROUND_LEFT, 188 launcher_background,
183 IDR_AURA_LAUNCHER_BACKGROUND_RIGHT)); 189 shelf->SelectValueForShelfAlignment(
184 paint.setAlpha(alpha_); 190 SkBitmapOperations::ROTATION_90_CW,
185 canvas->DrawImageInt( 191 SkBitmapOperations::ROTATION_90_CW,
186 *launcher_background, 192 SkBitmapOperations::ROTATION_270_CW));
187 0, 0, launcher_background->width(), launcher_background->height(), 193
188 0, 0, width(), height(), 194 gfx::Rect black_rect = shelf->SelectValueForShelfAlignment(
189 false, 195 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
190 paint); 196 gfx::Rect(0, 0, kNumBlackPixels, height()),
191 canvas->FillRect( 197 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
192 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), 198
193 SK_ColorBLACK); 199 SkPaint paint;
194 } else { 200 paint.setAlpha(alpha_);
195 // TODO(davemoore): when we get an image for the side launcher background 201 canvas->DrawImageInt(
196 // use it, and handle black border. 202 launcher_background,
197 canvas->DrawColor(SkColorSetARGB(alpha_, 0, 0, 0)); 203 0, 0, launcher_background.width(), launcher_background.height(),
198 } 204 0, 0, width(), height(),
205 false,
206 paint);
207 canvas->FillRect(black_rect, SK_ColorBLACK);
199 } 208 }
200 209
201 void Launcher::DelegateView::UpdateBackground(int alpha) { 210 void Launcher::DelegateView::UpdateBackground(int alpha) {
202 alpha_ = alpha; 211 alpha_ = alpha;
203 SchedulePaint(); 212 SchedulePaint();
204 } 213 }
205 214
206 // Launcher -------------------------------------------------------------------- 215 // Launcher --------------------------------------------------------------------
207 216
208 Launcher::Launcher(LauncherModel* launcher_model, 217 Launcher::Launcher(LauncherModel* launcher_model,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 if (focus_cycler) 276 if (focus_cycler)
268 focus_cycler->AddWidget(widget_.get()); 277 focus_cycler->AddWidget(widget_.get());
269 } 278 }
270 279
271 internal::FocusCycler* Launcher::GetFocusCycler() { 280 internal::FocusCycler* Launcher::GetFocusCycler() {
272 return delegate_view_->focus_cycler(); 281 return delegate_view_->focus_cycler();
273 } 282 }
274 283
275 void Launcher::SetAlignment(ShelfAlignment alignment) { 284 void Launcher::SetAlignment(ShelfAlignment alignment) {
276 alignment_ = alignment; 285 alignment_ = alignment;
286 delegate_view_->SchedulePaint();
277 launcher_view_->OnShelfAlignmentChanged(); 287 launcher_view_->OnShelfAlignmentChanged();
278 // ShelfLayoutManager will resize the launcher. 288 // ShelfLayoutManager will resize the launcher.
279 } 289 }
280 290
281 void Launcher::SetPaintsBackground( 291 void Launcher::SetPaintsBackground(
282 bool value, 292 bool value,
283 internal::BackgroundAnimator::ChangeType change_type) { 293 internal::BackgroundAnimator::ChangeType change_type) {
284 background_animator_.SetPaintsBackground(value, change_type); 294 background_animator_.SetPaintsBackground(value, change_type);
285 } 295 }
286 296
(...skipping 14 matching lines...) Expand all
301 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 311 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
302 params.parent = Shell::GetContainer( 312 params.parent = Shell::GetContainer(
303 window_container_->GetRootWindow(), 313 window_container_->GetRootWindow(),
304 ash::internal::kShellWindowId_LauncherContainer); 314 ash::internal::kShellWindowId_LauncherContainer);
305 params.accept_events = false; 315 params.accept_events = false;
306 dimmer_->Init(params); 316 dimmer_->Init(params);
307 dimmer_->GetNativeWindow()->SetName("LauncherDimmer"); 317 dimmer_->GetNativeWindow()->SetName("LauncherDimmer");
308 dimmer_->SetBounds(widget_->GetWindowBoundsInScreen()); 318 dimmer_->SetBounds(widget_->GetWindowBoundsInScreen());
309 // The launcher should not take focus when it is initially shown. 319 // The launcher should not take focus when it is initially shown.
310 dimmer_->set_focus_on_creation(false); 320 dimmer_->set_focus_on_creation(false);
311 dimmer_->SetContentsView(new DimmerView(widget_.get())); 321 dimmer_->SetContentsView(new DimmerView(this));
312 dimmer_->GetNativeView()->SetName("LauncherDimmerView"); 322 dimmer_->GetNativeView()->SetName("LauncherDimmerView");
313 dimmer_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, 323 dimmer_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey,
314 true); 324 true);
315 dimmer_->Show(); 325 dimmer_->Show();
316 } 326 }
317 327
318 bool Launcher::GetDimsShelf() const { 328 bool Launcher::GetDimsShelf() const {
319 return dimmer_.get() && dimmer_->IsVisible(); 329 return dimmer_.get() && dimmer_->IsVisible();
320 } 330 }
321 331
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } else { 433 } else {
424 delegate_view_->GetFocusManager()->ClearFocus(); 434 delegate_view_->GetFocusManager()->ClearFocus();
425 } 435 }
426 } 436 }
427 437
428 internal::LauncherView* Launcher::GetLauncherViewForTest() { 438 internal::LauncherView* Launcher::GetLauncherViewForTest() {
429 return launcher_view_; 439 return launcher_view_;
430 } 440 }
431 441
432 } // namespace ash 442 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher.h ('k') | ash/launcher/launcher_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698