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

Side by Side Diff: ash/wm/panel_layout_manager.cc

Issue 9808026: Layout panels on top of their launcher icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for review Created 8 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 | Annotate | Revision Log
« ash/wm/panel_layout_manager.h ('K') | « ash/wm/panel_layout_manager.h ('k') | no next file » | 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/wm/panel_layout_manager.h" 5 #include "ash/wm/panel_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/launcher/launcher.h" 9 #include "ash/launcher/launcher.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 18 matching lines...) Expand all
29 29
30 namespace ash { 30 namespace ash {
31 namespace internal { 31 namespace internal {
32 32
33 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
34 // PanelLayoutManager public implementation: 34 // PanelLayoutManager public implementation:
35 35
36 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) 36 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container)
37 : panel_container_(panel_container), 37 : panel_container_(panel_container),
38 in_layout_(false), 38 in_layout_(false),
39 dragged_panel_(NULL) { 39 dragged_panel_(NULL),
40 ALLOW_THIS_IN_INITIALIZER_LIST(launcher_icons_observer_(this)){
40 DCHECK(panel_container); 41 DCHECK(panel_container);
41 } 42 }
42 43
43 PanelLayoutManager::~PanelLayoutManager() { 44 PanelLayoutManager::~PanelLayoutManager() {
45 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
46 if (launcher != NULL)
47 launcher->RemoveIconsObserver(&launcher_icons_observer_);
44 } 48 }
45 49
46 void PanelLayoutManager::StartDragging(aura::Window* panel) { 50 void PanelLayoutManager::StartDragging(aura::Window* panel) {
47 DCHECK(dragged_panel_ == NULL); 51 DCHECK(dragged_panel_ == NULL);
48 DCHECK(panel->parent() == panel_container_); 52 DCHECK(panel->parent() == panel_container_);
49 dragged_panel_ = panel; 53 dragged_panel_ = panel;
50 } 54 }
51 55
52 void PanelLayoutManager::FinishDragging() { 56 void PanelLayoutManager::FinishDragging() {
53 DCHECK(dragged_panel_ != NULL); 57 DCHECK(dragged_panel_ != NULL);
54 dragged_panel_ = NULL; 58 dragged_panel_ = NULL;
55 Relayout(); 59 Relayout();
56 } 60 }
57 61
62 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) {
63 launcher->AddIconsObserver(&launcher_icons_observer_);
64 }
65
58 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { 66 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
59 DCHECK(panel->parent() == panel_container_); 67 DCHECK(panel->parent() == panel_container_);
60 if (panel->GetProperty(aura::client::kShowStateKey) == 68 if (panel->GetProperty(aura::client::kShowStateKey) ==
61 ui::SHOW_STATE_MINIMIZED) { 69 ui::SHOW_STATE_MINIMIZED) {
62 const gfx::Rect& old_bounds = panel->bounds(); 70 const gfx::Rect& old_bounds = panel->bounds();
63 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 71 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
64 72
65 gfx::Rect new_bounds(old_bounds); 73 gfx::Rect new_bounds(old_bounds);
66 const gfx::Rect* restore_bounds = GetRestoreBounds(panel); 74 const gfx::Rect* restore_bounds = GetRestoreBounds(panel);
67 if (restore_bounds != NULL) { 75 if (restore_bounds != NULL) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 149 }
142 } 150 }
143 151
144 SetChildBoundsDirect(child, bounds); 152 SetChildBoundsDirect(child, bounds);
145 Relayout(); 153 Relayout();
146 } 154 }
147 155
148 //////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////
149 // PanelLayoutManager private implementation: 157 // PanelLayoutManager private implementation:
150 158
159 PanelLayoutManager::LauncherIconsObserver::LauncherIconsObserver(
160 PanelLayoutManager* layout_manager)
161 : layout_manager_(layout_manager) {
162 }
163
164 void PanelLayoutManager::LauncherIconsObserver
165 ::OnLauncherIconPositionsChanged() {
166 layout_manager_->Relayout();
167 }
168
151 // This is a rough outline of a simple panel layout manager. 169 // This is a rough outline of a simple panel layout manager.
152 void PanelLayoutManager::Relayout() { 170 void PanelLayoutManager::Relayout() {
153 if (in_layout_) 171 if (in_layout_)
154 return; 172 return;
155 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 173 AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
156 174
157 // Panels are currently laid out just above the launcher (if it exists),
158 // otherwise at the bottom of the root window.
159 int right, bottom;
160 ash::Shell* shell = ash::Shell::GetInstance(); 175 ash::Shell* shell = ash::Shell::GetInstance();
161 if (shell->launcher() && shell->launcher()->widget()->IsVisible()) {
162 const gfx::Rect& bounds =
163 shell->launcher()->widget()->GetWindowScreenBounds();
164 right = bounds.width() - 1 - kPanelMarginEdge;
165 bottom = bounds.y() - 1;
166 } else {
167 const gfx::Rect& bounds = panel_container_->GetRootWindow()->bounds();
168 right = bounds.width() - 1 - kPanelMarginEdge;
169 bottom = bounds.bottom() - 1;
170 }
171 176
172 // Layout the panel windows right to left.
173 for (PanelList::iterator iter = panel_windows_.begin(); 177 for (PanelList::iterator iter = panel_windows_.begin();
174 iter != panel_windows_.end(); ++iter) { 178 iter != panel_windows_.end(); ++iter) {
175 aura::Window* panel_win = *iter; 179 aura::Window* panel_win = *iter;
180 gfx::Rect icon_rect =
181 shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win);
182
183 if (icon_rect.width() == 0 && icon_rect.height() == 0)
stevenjb 2012/04/03 20:59:28 I believe this happens when the icon is not visibl
Dmitry Lomov (no reviews) 2012/04/03 21:18:23 Right, and used does not get any notification on i
184 continue;
185
186 gfx::Point icon_origin = icon_rect.origin();
187 aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(),
188 panel_container_, &icon_origin);
stevenjb 2012/04/03 20:59:28 icon_origin only appears to be needed in the if bl
Dmitry Lomov (no reviews) 2012/04/03 21:18:23 You are right.
189
176 if (!panel_win->IsVisible()) 190 if (!panel_win->IsVisible())
stevenjb 2012/04/03 20:59:28 We should probably move this early exit up to imme
Dmitry Lomov (no reviews) 2012/04/03 21:18:23 Right again.
177 continue; 191 continue;
178 int x = right - panel_win->bounds().width();
179 int y = bottom - panel_win->bounds().height();
180 192
181 // Do not relayout dragged panel, but pretend it is in place 193 // Do not relayout dragged panel, but pretend it is in place
182 if (panel_win != dragged_panel_) { 194 if (panel_win != dragged_panel_) {
183 gfx::Rect bounds(x, y, 195 gfx::Rect current_bounds = panel_win->bounds();
184 panel_win->bounds().width(), 196
185 panel_win->bounds().height()); 197 gfx::Rect bounds(
198 icon_origin.x() + icon_rect.width()/2 - current_bounds.width()/2,
199 icon_origin.y() - current_bounds.height(),
200 current_bounds.width(),
201 current_bounds.height());
186 SetChildBoundsDirect(panel_win, bounds); 202 SetChildBoundsDirect(panel_win, bounds);
187 } 203 }
188 right = x - kPanelMarginMiddle;
189 } 204 }
190 } 205 }
191 206
192 } // namespace internal 207 } // namespace internal
193 } // namespace ash 208 } // namespace ash
OLDNEW
« ash/wm/panel_layout_manager.h ('K') | « ash/wm/panel_layout_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698