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

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: Ununsed constanrs removed Created 8 years, 9 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/launcher/launcher_model.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/wm/property_util.h" 12 #include "ash/wm/property_util.h"
12 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
13 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
15 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
16 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h" 18 #include "ui/gfx/size.h"
18 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
19 20
20 namespace { 21 namespace {
21 const int kPanelMarginEdge = 4; 22 const int kPanelMarginEdge = 4;
22 const int kPanelMarginMiddle = 8; 23 const int kPanelMarginMiddle = 8;
23 24
24 const int kMinimizedHeight = 24; 25 const int kMinimizedHeight = 24;
25 26
26 const float kMaxHeightFactor = .80f; 27 const float kMaxHeightFactor = .80f;
27 const float kMaxWidthFactor = .50f; 28 const float kMaxWidthFactor = .50f;
28 } 29 }
29 30
30 namespace ash { 31 namespace ash {
31 namespace internal { 32 namespace internal {
32 33
33 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
34 // PanelLayoutManager public implementation: 35 // PanelLayoutManager public implementation:
35 36
36 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) 37 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container)
37 : panel_container_(panel_container), 38 : panel_container_(panel_container),
38 in_layout_(false), 39 in_layout_(false),
39 dragged_panel_(NULL) { 40 dragged_panel_(NULL),
41 ALLOW_THIS_IN_INITIALIZER_LIST(launcher_icons_observer_(this)){
40 DCHECK(panel_container); 42 DCHECK(panel_container);
41 } 43 }
42 44
43 PanelLayoutManager::~PanelLayoutManager() { 45 PanelLayoutManager::~PanelLayoutManager() {
46 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
sky 2012/03/23 21:41:14 Did you make sure this is deleted before the launc
Dmitry Lomov (no reviews) 2012/03/23 22:34:38 Hopefully the getter will return null?
47 if (launcher != NULL)
48 launcher->RemoveIconsObserver(&launcher_icons_observer_);
44 } 49 }
45 50
46 void PanelLayoutManager::StartDragging(aura::Window* panel) { 51 void PanelLayoutManager::StartDragging(aura::Window* panel) {
47 DCHECK(dragged_panel_ == NULL); 52 DCHECK(dragged_panel_ == NULL);
48 DCHECK(panel->parent() == panel_container_); 53 DCHECK(panel->parent() == panel_container_);
49 dragged_panel_ = panel; 54 dragged_panel_ = panel;
50 } 55 }
51 56
52 void PanelLayoutManager::FinishDragging() { 57 void PanelLayoutManager::FinishDragging() {
53 DCHECK(dragged_panel_ != NULL); 58 DCHECK(dragged_panel_ != NULL);
54 dragged_panel_ = NULL; 59 dragged_panel_ = NULL;
55 Relayout(); 60 Relayout();
56 } 61 }
57 62
63 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) {
64 launcher->AddIconsObserver(&launcher_icons_observer_);
65 }
66
58 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { 67 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
59 DCHECK(panel->parent() == panel_container_); 68 DCHECK(panel->parent() == panel_container_);
60 if (panel->GetProperty(aura::client::kShowStateKey) == 69 if (panel->GetProperty(aura::client::kShowStateKey) ==
61 ui::SHOW_STATE_MINIMIZED) { 70 ui::SHOW_STATE_MINIMIZED) {
62 const gfx::Rect& old_bounds = panel->bounds(); 71 const gfx::Rect& old_bounds = panel->bounds();
63 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 72 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
64 73
65 gfx::Rect new_bounds(old_bounds); 74 gfx::Rect new_bounds(old_bounds);
66 const gfx::Rect* restore_bounds = GetRestoreBounds(panel); 75 const gfx::Rect* restore_bounds = GetRestoreBounds(panel);
67 if (restore_bounds != NULL) { 76 if (restore_bounds != NULL) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 156
148 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
149 // PanelLayoutManager private implementation: 158 // PanelLayoutManager private implementation:
150 159
151 // This is a rough outline of a simple panel layout manager. 160 // This is a rough outline of a simple panel layout manager.
152 void PanelLayoutManager::Relayout() { 161 void PanelLayoutManager::Relayout() {
153 if (in_layout_) 162 if (in_layout_)
154 return; 163 return;
155 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 164 AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
156 165
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(); 166 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 167
172 // Layout the panel windows right to left.
173 for (PanelList::iterator iter = panel_windows_.begin(); 168 for (PanelList::iterator iter = panel_windows_.begin();
174 iter != panel_windows_.end(); ++iter) { 169 iter != panel_windows_.end(); ++iter) {
175 aura::Window* panel_win = *iter; 170 aura::Window* panel_win = *iter;
171 gfx::Rect icon_rect =
172 shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win);
sky 2012/03/23 21:41:14 This may be empty.
Dmitry Lomov (no reviews) 2012/03/23 22:34:38 True. The layout manager has no idea what to do in
173 gfx::Point icon_origin = icon_rect.origin();
174 aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(),
175 panel_container_, &icon_origin);
176
176 if (!panel_win->IsVisible()) 177 if (!panel_win->IsVisible())
177 continue; 178 continue;
178 int x = right - panel_win->bounds().width();
179 int y = bottom - panel_win->bounds().height();
180 179
181 // Do not relayout dragged panel, but pretend it is in place 180 // Do not relayout dragged panel, but pretend it is in place
182 if (panel_win != dragged_panel_) { 181 if (panel_win != dragged_panel_) {
183 gfx::Rect bounds(x, y, 182 gfx::Rect current_bounds = panel_win->bounds();
184 panel_win->bounds().width(), 183
185 panel_win->bounds().height()); 184 gfx::Rect bounds(
185 icon_origin.x() + icon_rect.width()/2 - current_bounds.width()/2,
186 icon_origin.y() - current_bounds.height(),
187 current_bounds.width(),
188 current_bounds.height());
186 SetChildBoundsDirect(panel_win, bounds); 189 SetChildBoundsDirect(panel_win, bounds);
187 } 190 }
188 right = x - kPanelMarginMiddle;
189 } 191 }
190 } 192 }
191 193
192 } // namespace internal 194 } // namespace internal
193 } // namespace ash 195 } // 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