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

Side by Side Diff: ash/shelf/shelf_widget.cc

Issue 115113006: Rename Launcher to Shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ShelfTestAPI Created 7 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
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/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/session_state_delegate.h" 10 #include "ash/session_state_delegate.h"
(...skipping 20 matching lines...) Expand all
31 #include "ui/events/event_constants.h" 31 #include "ui/events/event_constants.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/image/image_skia_operations.h" 34 #include "ui/gfx/image/image_skia_operations.h"
35 #include "ui/gfx/skbitmap_operations.h" 35 #include "ui/gfx/skbitmap_operations.h"
36 #include "ui/views/accessible_pane_view.h" 36 #include "ui/views/accessible_pane_view.h"
37 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
38 #include "ui/views/widget/widget_delegate.h" 38 #include "ui/views/widget/widget_delegate.h"
39 39
40 namespace { 40 namespace {
41 // Size of black border at bottom (or side) of launcher. 41 // Size of black border at bottom (or side) of shelf.
42 const int kNumBlackPixels = 3; 42 const int kNumBlackPixels = 3;
43 // Alpha to paint dimming image with. 43 // Alpha to paint dimming image with.
44 const int kDimAlpha = 128; 44 const int kDimAlpha = 128;
45 45
46 // The time to dim and un-dim. 46 // The time to dim and un-dim.
47 const int kTimeToDimMs = 3000; // Slow in dimming. 47 const int kTimeToDimMs = 3000; // Slow in dimming.
48 const int kTimeToUnDimMs = 200; // Fast in activating. 48 const int kTimeToUnDimMs = 200; // Fast in activating.
49 49
50 // Class used to slightly dim shelf items when maximized and visible. 50 // Class used to slightly dim shelf items when maximized and visible.
51 class DimmerView : public views::View, 51 class DimmerView : public views::View,
(...skipping 26 matching lines...) Expand all
78 SchedulePaint(); 78 SchedulePaint();
79 } 79 }
80 80
81 // views::View overrides: 81 // views::View overrides:
82 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 82 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
83 83
84 // A function to test the current alpha used. 84 // A function to test the current alpha used.
85 int get_dimming_alpha_for_test() { return alpha_; } 85 int get_dimming_alpha_for_test() { return alpha_; }
86 86
87 private: 87 private:
88 // This class monitors mouse events to see if it is on top of the launcher. 88 // This class monitors mouse events to see if it is on top of the shelf.
89 class DimmerEventFilter : public ui::EventHandler { 89 class DimmerEventFilter : public ui::EventHandler {
90 public: 90 public:
91 explicit DimmerEventFilter(DimmerView* owner); 91 explicit DimmerEventFilter(DimmerView* owner);
92 virtual ~DimmerEventFilter(); 92 virtual ~DimmerEventFilter();
93 93
94 // Overridden from ui::EventHandler: 94 // Overridden from ui::EventHandler:
95 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 95 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
96 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 96 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
97 97
98 private: 98 private:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool previous = force_hovered_; 167 bool previous = force_hovered_;
168 force_hovered_ = force; 168 force_hovered_ = force;
169 // If the forced change does change the result we apply the change. 169 // If the forced change does change the result we apply the change.
170 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) 170 if (is_hovered_ || force_hovered_ != is_hovered_ || previous)
171 SetHovered(is_hovered_); 171 SetHovered(is_hovered_);
172 } 172 }
173 173
174 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { 174 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) {
175 SkPaint paint; 175 SkPaint paint;
176 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 176 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
177 gfx::ImageSkia launcher_background = 177 gfx::ImageSkia shelf_background =
178 *rb.GetImageNamed(IDR_AURA_LAUNCHER_DIMMING).ToImageSkia(); 178 *rb.GetImageNamed(IDR_AURA_LAUNCHER_DIMMING).ToImageSkia();
179 179
180 if (shelf_->GetAlignment() != ash::SHELF_ALIGNMENT_BOTTOM) { 180 if (shelf_->GetAlignment() != ash::SHELF_ALIGNMENT_BOTTOM) {
181 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( 181 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
182 launcher_background, 182 shelf_background,
183 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 183 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
184 SkBitmapOperations::ROTATION_90_CW, 184 SkBitmapOperations::ROTATION_90_CW,
185 SkBitmapOperations::ROTATION_90_CW, 185 SkBitmapOperations::ROTATION_90_CW,
186 SkBitmapOperations::ROTATION_270_CW, 186 SkBitmapOperations::ROTATION_270_CW,
187 SkBitmapOperations::ROTATION_180_CW)); 187 SkBitmapOperations::ROTATION_180_CW));
188 } 188 }
189 paint.setAlpha(alpha_); 189 paint.setAlpha(alpha_);
190 canvas->DrawImageInt( 190 canvas->DrawImageInt(shelf_background,
191 launcher_background, 191 0,
192 0, 0, launcher_background.width(), launcher_background.height(), 192 0,
193 0, 0, width(), height(), 193 shelf_background.width(),
194 false, 194 shelf_background.height(),
195 paint); 195 0,
196 0,
197 width(),
198 height(),
199 false,
200 paint);
196 } 201 }
197 202
198 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) 203 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner)
199 : owner_(owner), 204 : owner_(owner),
200 mouse_inside_(false), 205 mouse_inside_(false),
201 touch_inside_(false) { 206 touch_inside_(false) {
202 ash::Shell::GetInstance()->AddPreTargetHandler(this); 207 ash::Shell::GetInstance()->AddPreTargetHandler(this);
203 } 208 }
204 209
205 DimmerView::DimmerEventFilter::~DimmerEventFilter() { 210 DimmerView::DimmerEventFilter::~DimmerEventFilter() {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 views::Widget::InitParams params( 350 views::Widget::InitParams params(
346 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 351 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
347 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 352 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
348 params.can_activate = false; 353 params.can_activate = false;
349 params.accept_events = false; 354 params.accept_events = false;
350 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 355 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
351 params.parent = shelf_->GetNativeView(); 356 params.parent = shelf_->GetNativeView();
352 dimmer_->Init(params); 357 dimmer_->Init(params);
353 dimmer_->GetNativeWindow()->SetName("ShelfDimmer"); 358 dimmer_->GetNativeWindow()->SetName("ShelfDimmer");
354 dimmer_->SetBounds(shelf_->GetWindowBoundsInScreen()); 359 dimmer_->SetBounds(shelf_->GetWindowBoundsInScreen());
355 // The launcher should not take focus when it is initially shown. 360 // The shelf should not take focus when it is initially shown.
356 dimmer_->set_focus_on_creation(false); 361 dimmer_->set_focus_on_creation(false);
357 dimmer_view_ = new DimmerView(shelf_, disable_dimming_animations_for_test_); 362 dimmer_view_ = new DimmerView(shelf_, disable_dimming_animations_for_test_);
358 dimmer_->SetContentsView(dimmer_view_); 363 dimmer_->SetContentsView(dimmer_view_);
359 dimmer_->GetNativeView()->SetName("ShelfDimmerView"); 364 dimmer_->GetNativeView()->SetName("ShelfDimmerView");
360 dimmer_->Show(); 365 dimmer_->Show();
361 shelf_->GetNativeView()->AddObserver(this); 366 shelf_->GetNativeView()->AddObserver(this);
362 } else { 367 } else {
363 // Some unit tests will come here with a destroyed window. 368 // Some unit tests will come here with a destroyed window.
364 if (shelf_->GetNativeView()) 369 if (shelf_->GetNativeView())
365 shelf_->GetNativeView()->RemoveObserver(this); 370 shelf_->GetNativeView()->RemoveObserver(this);
366 dimmer_view_ = NULL; 371 dimmer_view_ = NULL;
367 dimmer_.reset(NULL); 372 dimmer_.reset(NULL);
368 } 373 }
369 } 374 }
370 375
371 bool ShelfWidget::DelegateView::GetDimmed() const { 376 bool ShelfWidget::DelegateView::GetDimmed() const {
372 return dimmer_.get() && dimmer_->IsVisible(); 377 return dimmer_.get() && dimmer_->IsVisible();
373 } 378 }
374 379
375 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { 380 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
376 layer->Add(&opaque_background_); 381 layer->Add(&opaque_background_);
377 ReorderLayers(); 382 ReorderLayers();
378 } 383 }
379 384
380 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 385 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
381 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 386 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
382 gfx::ImageSkia launcher_background = 387 gfx::ImageSkia shelf_background =
383 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); 388 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND);
384 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) 389 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment())
385 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( 390 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
386 launcher_background, 391 shelf_background,
387 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 392 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
388 SkBitmapOperations::ROTATION_90_CW, 393 SkBitmapOperations::ROTATION_90_CW,
389 SkBitmapOperations::ROTATION_90_CW, 394 SkBitmapOperations::ROTATION_90_CW,
390 SkBitmapOperations::ROTATION_270_CW, 395 SkBitmapOperations::ROTATION_270_CW,
391 SkBitmapOperations::ROTATION_180_CW)); 396 SkBitmapOperations::ROTATION_180_CW));
392 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); 397 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
393 SkPaint paint; 398 SkPaint paint;
394 paint.setAlpha(alpha_); 399 paint.setAlpha(alpha_);
395 canvas->DrawImageInt( 400 canvas->DrawImageInt(shelf_background,
396 launcher_background, 401 0,
397 0, 0, launcher_background.width(), launcher_background.height(), 402 0,
398 (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && 403 shelf_background.width(),
399 dock_bounds.x() == 0 && dock_bounds.width() > 0) ? 404 shelf_background.height(),
400 dock_bounds.width() : 0, 0, 405 (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() &&
401 SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() ? 406 dock_bounds.x() == 0 && dock_bounds.width() > 0)
402 width() - dock_bounds.width() : width(), height(), 407 ? dock_bounds.width()
403 false, 408 : 0,
404 paint); 409 0,
410 SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment()
411 ? width() - dock_bounds.width()
412 : width(),
413 height(),
414 false,
415 paint);
405 if (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && 416 if (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() &&
406 dock_bounds.width() > 0) { 417 dock_bounds.width() > 0) {
407 // The part of the shelf background that is in the corner below the docked 418 // The part of the shelf background that is in the corner below the docked
408 // windows close to the work area is an arched gradient that blends 419 // windows close to the work area is an arched gradient that blends
409 // vertically oriented docked background and horizontal shelf. 420 // vertically oriented docked background and horizontal shelf.
410 gfx::ImageSkia launcher_corner = 421 gfx::ImageSkia shelf_corner =
411 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_CORNER); 422 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_CORNER);
412 if (dock_bounds.x() == 0) { 423 if (dock_bounds.x() == 0) {
413 launcher_corner = gfx::ImageSkiaOperations::CreateRotatedImage( 424 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
414 launcher_corner, SkBitmapOperations::ROTATION_90_CW); 425 shelf_corner, SkBitmapOperations::ROTATION_90_CW);
415 } 426 }
416 canvas->DrawImageInt( 427 canvas->DrawImageInt(
417 launcher_corner, 428 shelf_corner,
418 0, 0, launcher_corner.width(), launcher_corner.height(), 429 0,
430 0,
431 shelf_corner.width(),
432 shelf_corner.height(),
419 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), 433 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(),
420 0, 434 0,
421 height(), height(), 435 height(),
436 height(),
422 false, 437 false,
423 paint); 438 paint);
424 // The part of the shelf background that is just below the docked windows 439 // The part of the shelf background that is just below the docked windows
425 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. 440 // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
426 // This avoids showing the border 3D shadow between the shelf and the dock. 441 // This avoids showing the border 3D shadow between the shelf and the dock.
427 canvas->DrawImageInt( 442 canvas->DrawImageInt(shelf_background,
428 launcher_background, 443 0,
429 0, launcher_background.height() - 1, launcher_background.width(), 1, 444 shelf_background.height() - 1,
430 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, 0, 445 shelf_background.width(),
431 dock_bounds.width() - height(), height(), 446 1,
432 false, 447 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
433 paint); 448 0,
449 dock_bounds.width() - height(),
450 height(),
451 false,
452 paint);
434 } 453 }
435 gfx::Rect black_rect = 454 gfx::Rect black_rect =
436 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 455 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
437 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), 456 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
438 gfx::Rect(0, 0, kNumBlackPixels, height()), 457 gfx::Rect(0, 0, kNumBlackPixels, height()),
439 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), 458 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()),
440 gfx::Rect(0, 0, width(), kNumBlackPixels)); 459 gfx::Rect(0, 0, width(), kNumBlackPixels));
441 canvas->FillRect(black_rect, SK_ColorBLACK); 460 canvas->FillRect(black_rect, SK_ColorBLACK);
442 } 461 }
443 462
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 625
607 DCHECK(false); 626 DCHECK(false);
608 return false; 627 return false;
609 } 628 }
610 629
611 ShelfAlignment ShelfWidget::GetAlignment() const { 630 ShelfAlignment ShelfWidget::GetAlignment() const {
612 return shelf_layout_manager_->GetAlignment(); 631 return shelf_layout_manager_->GetAlignment();
613 } 632 }
614 633
615 void ShelfWidget::SetAlignment(ShelfAlignment alignment) { 634 void ShelfWidget::SetAlignment(ShelfAlignment alignment) {
616 if (launcher_) 635 if (shelf_)
617 launcher_->SetAlignment(alignment); 636 shelf_->SetAlignment(alignment);
618 status_area_widget_->SetShelfAlignment(alignment); 637 status_area_widget_->SetShelfAlignment(alignment);
619 delegate_view_->SchedulePaint(); 638 delegate_view_->SchedulePaint();
620 } 639 }
621 640
622 void ShelfWidget::SetDimsShelf(bool dimming) { 641 void ShelfWidget::SetDimsShelf(bool dimming) {
623 delegate_view_->SetDimmed(dimming); 642 delegate_view_->SetDimmed(dimming);
624 // Repaint all children, allowing updates to reflect dimmed state eg: 643 // Repaint all children, allowing updates to reflect dimmed state eg:
625 // status area background, app list button and overflow button. 644 // status area background, app list button and overflow button.
626 if (launcher_) 645 if (shelf_)
627 launcher_->SchedulePaint(); 646 shelf_->SchedulePaint();
628 status_area_widget_->GetContentsView()->SchedulePaint(); 647 status_area_widget_->GetContentsView()->SchedulePaint();
629 } 648 }
630 649
631 bool ShelfWidget::GetDimsShelf() const { 650 bool ShelfWidget::GetDimsShelf() const {
632 return delegate_view_->GetDimmed(); 651 return delegate_view_->GetDimmed();
633 } 652 }
634 653
635 void ShelfWidget::CreateLauncher() { 654 void ShelfWidget::CreateShelf() {
636 if (launcher_) 655 if (shelf_)
637 return; 656 return;
638 657
639 Shell* shell = Shell::GetInstance(); 658 Shell* shell = Shell::GetInstance();
640 // This needs to be called before shelf_model(). 659 // This needs to be called before shelf_model().
641 ShelfDelegate* shelf_delegate = shell->GetShelfDelegate(); 660 ShelfDelegate* shelf_delegate = shell->GetShelfDelegate();
642 if (!shelf_delegate) 661 if (!shelf_delegate)
643 return; // Not ready to create Launcher 662 return; // Not ready to create Shelf.
644 663
645 launcher_.reset(new Launcher(shell->shelf_model(), 664 shelf_.reset(
646 shell->GetShelfDelegate(), 665 new Shelf(shell->shelf_model(), shell->GetShelfDelegate(), this));
647 this));
648 SetFocusCycler(shell->focus_cycler()); 666 SetFocusCycler(shell->focus_cycler());
649 667
650 // Inform the root window controller. 668 // Inform the root window controller.
651 internal::RootWindowController::ForWindow(window_container_)-> 669 internal::RootWindowController::ForWindow(window_container_)
652 OnLauncherCreated(); 670 ->OnShelfCreated();
653 671
654 launcher_->SetVisible( 672 shelf_->SetVisible(
655 shell->session_state_delegate()->IsActiveUserSessionStarted()); 673 shell->session_state_delegate()->IsActiveUserSessionStarted());
656 shelf_layout_manager_->LayoutShelf(); 674 shelf_layout_manager_->LayoutShelf();
657 Show(); 675 Show();
658 } 676 }
659 677
660 bool ShelfWidget::IsLauncherVisible() const { 678 bool ShelfWidget::IsShelfVisible() const {
661 return launcher_.get() && launcher_->IsVisible(); 679 return shelf_.get() && shelf_->IsVisible();
662 } 680 }
663 681
664 void ShelfWidget::SetLauncherVisibility(bool visible) { 682 void ShelfWidget::SetShelfVisibility(bool visible) {
665 if (launcher_) 683 if (shelf_)
666 launcher_->SetVisible(visible); 684 shelf_->SetVisible(visible);
667 } 685 }
668 686
669 void ShelfWidget::SetFocusCycler(internal::FocusCycler* focus_cycler) { 687 void ShelfWidget::SetFocusCycler(internal::FocusCycler* focus_cycler) {
670 delegate_view_->set_focus_cycler(focus_cycler); 688 delegate_view_->set_focus_cycler(focus_cycler);
671 if (focus_cycler) 689 if (focus_cycler)
672 focus_cycler->AddWidget(this); 690 focus_cycler->AddWidget(this);
673 } 691 }
674 692
675 internal::FocusCycler* ShelfWidget::GetFocusCycler() { 693 internal::FocusCycler* ShelfWidget::GetFocusCycler() {
676 return delegate_view_->focus_cycler(); 694 return delegate_view_->focus_cycler();
(...skipping 29 matching lines...) Expand all
706 return delegate_view_->GetDimmerBoundsForTest(); 724 return delegate_view_->GetDimmerBoundsForTest();
707 return gfx::Rect(); 725 return gfx::Rect();
708 } 726 }
709 727
710 void ShelfWidget::DisableDimmingAnimationsForTest() { 728 void ShelfWidget::DisableDimmingAnimationsForTest() {
711 DCHECK(delegate_view_); 729 DCHECK(delegate_view_);
712 return delegate_view_->disable_dimming_animations_for_test(); 730 return delegate_view_->disable_dimming_animations_for_test();
713 } 731 }
714 732
715 } // namespace ash 733 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698