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

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

Issue 1851883002: Cleanup shelf initialization and observation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check for shelf before setting prefs in ChromeLauncherController. Created 4 years, 8 months 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
« no previous file with comments | « ash/shelf/shelf.h ('k') | ash/shelf/shelf_alignment_menu.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "ash/shelf/shelf.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"
(...skipping 24 matching lines...) Expand all
35 #include "ui/views/widget/widget_delegate.h" 35 #include "ui/views/widget/widget_delegate.h"
36 #include "ui/wm/public/activation_client.h" 36 #include "ui/wm/public/activation_client.h"
37 37
38 namespace ash { 38 namespace ash {
39 39
40 const char Shelf::kNativeViewName[] = "ShelfView"; 40 const char Shelf::kNativeViewName[] = "ShelfView";
41 41
42 Shelf::Shelf(ShelfModel* shelf_model, 42 Shelf::Shelf(ShelfModel* shelf_model,
43 ShelfDelegate* shelf_delegate, 43 ShelfDelegate* shelf_delegate,
44 ShelfWidget* shelf_widget) 44 ShelfWidget* shelf_widget)
45 : shelf_view_(NULL), 45 : shelf_view_(nullptr),
46 alignment_(shelf_widget->GetAlignment()), 46 alignment_(SHELF_ALIGNMENT_BOTTOM),
47 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
47 delegate_(shelf_delegate), 48 delegate_(shelf_delegate),
48 shelf_widget_(shelf_widget) { 49 shelf_widget_(shelf_widget) {
49 shelf_view_ = new ShelfView(shelf_model, delegate_, this); 50 shelf_view_ = new ShelfView(shelf_model, delegate_, this);
50 shelf_view_->Init(); 51 shelf_view_->Init();
51 shelf_widget_->GetContentsView()->AddChildView(shelf_view_); 52 shelf_widget_->GetContentsView()->AddChildView(shelf_view_);
52 shelf_widget_->GetNativeView()->SetName(kNativeViewName); 53 shelf_widget_->GetNativeView()->SetName(kNativeViewName);
53 delegate_->OnShelfCreated(this);
54 } 54 }
55 55
56 Shelf::~Shelf() { 56 Shelf::~Shelf() {
57 delegate_->OnShelfDestroyed(this); 57 delegate_->OnShelfDestroyed(this);
58 } 58 }
59 59
60 // static 60 // static
61 Shelf* Shelf::ForPrimaryDisplay() { 61 Shelf* Shelf::ForPrimaryDisplay() {
62 return Shelf::ForWindow(Shell::GetPrimaryRootWindow()); 62 return Shelf::ForWindow(Shell::GetPrimaryRootWindow());
63 } 63 }
64 64
65 // static 65 // static
66 Shelf* Shelf::ForWindow(const aura::Window* window) { 66 Shelf* Shelf::ForWindow(const aura::Window* window) {
67 ShelfWidget* shelf_widget = RootWindowController::ForWindow(window)->shelf(); 67 ShelfWidget* shelf_widget = RootWindowController::ForWindow(window)->shelf();
68 return shelf_widget ? shelf_widget->shelf() : NULL; 68 return shelf_widget ? shelf_widget->shelf() : nullptr;
69 } 69 }
70 70
71 void Shelf::SetAlignment(ShelfAlignment alignment) { 71 void Shelf::SetAlignment(ShelfAlignment alignment) {
72 if (alignment_ == alignment)
73 return;
74
72 alignment_ = alignment; 75 alignment_ = alignment;
73 shelf_view_->OnShelfAlignmentChanged(); 76 shelf_view_->OnShelfAlignmentChanged();
77 shelf_widget_->OnShelfAlignmentChanged();
78 delegate_->OnShelfAlignmentChanged(this);
79 Shell::GetInstance()->OnShelfAlignmentChanged(
80 shelf_widget_->GetNativeWindow()->GetRootWindow());
74 // ShelfLayoutManager will resize the shelf. 81 // ShelfLayoutManager will resize the shelf.
75 } 82 }
76 83
84 ShelfAlignment Shelf::GetAlignment() const {
85 // Bottom alignment is forced when the screen is locked or a user gets added.
86 bool locked = shelf_widget_->shelf_layout_manager()->IsAlignmentLocked();
87 return locked ? SHELF_ALIGNMENT_BOTTOM : alignment_;
sky 2016/04/04 22:44:32 Seems unusual to force an alignment like this. Cou
88 }
89
77 bool Shelf::IsHorizontalAlignment() const { 90 bool Shelf::IsHorizontalAlignment() const {
78 return alignment_ == SHELF_ALIGNMENT_BOTTOM; 91 return alignment_ == SHELF_ALIGNMENT_BOTTOM;
79 } 92 }
80 93
81 void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { 94 void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) {
82 shelf_widget_->shelf_layout_manager()->SetAutoHideBehavior(behavior); 95 if (auto_hide_behavior_ == auto_hide_behavior)
96 return;
97
98 auto_hide_behavior_ = auto_hide_behavior;
99 delegate_->OnShelfAutoHideBehaviorChanged(this);
100 Shell::GetInstance()->OnShelfAutoHideBehaviorChanged(
101 shelf_widget_->GetNativeWindow()->GetRootWindow());
83 } 102 }
84 103
85 ShelfAutoHideBehavior Shelf::GetAutoHideBehavior() const { 104 ShelfAutoHideBehavior Shelf::GetAutoHideBehavior() const {
86 return shelf_widget_->shelf_layout_manager()->auto_hide_behavior(); 105 return auto_hide_behavior_;
87 } 106 }
88 107
89 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow( 108 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(
90 const aura::Window* window) { 109 const aura::Window* window) {
91 ShelfID id = GetShelfIDForWindow(window); 110 ShelfID id = GetShelfIDForWindow(window);
92 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); 111 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id));
93 gfx::Point screen_origin; 112 gfx::Point screen_origin;
94 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); 113 views::View::ConvertPointToScreen(shelf_view_, &screen_origin);
95 return gfx::Rect(screen_origin.x() + bounds.x(), 114 return gfx::Rect(screen_origin.x() + bounds.x(),
96 screen_origin.y() + bounds.y(), 115 screen_origin.y() + bounds.y(),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 205
187 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { 206 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const {
188 return shelf_view_->GetVisibleItemsBoundsInScreen(); 207 return shelf_view_->GetVisibleItemsBoundsInScreen();
189 } 208 }
190 209
191 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { 210 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() {
192 return shelf_view_; 211 return shelf_view_;
193 } 212 }
194 213
195 } // namespace ash 214 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf.h ('k') | ash/shelf/shelf_alignment_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698