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

Side by Side Diff: chrome/browser/ui/panels/panel_manager.cc

Issue 9560002: Cleanup to keep panel from manipulating its panel strip assignment directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed final nits 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
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 "chrome/browser/ui/panels/panel_manager.h" 5 #include "chrome/browser/ui/panels/panel_manager.h"
6 6
7 #include "base/auto_reset.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/fullscreen.h" 11 #include "chrome/browser/fullscreen.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/panels/detached_panel_strip.h" 14 #include "chrome/browser/ui/panels/detached_panel_strip.h"
14 #include "chrome/browser/ui/panels/docked_panel_strip.h" 15 #include "chrome/browser/ui/panels/docked_panel_strip.h"
15 #include "chrome/browser/ui/panels/overflow_panel_strip.h" 16 #include "chrome/browser/ui/panels/overflow_panel_strip.h"
16 #include "chrome/browser/ui/panels/panel_drag_controller.h" 17 #include "chrome/browser/ui/panels/panel_drag_controller.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || 58 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") ||
58 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); 59 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj");
59 } 60 }
60 61
61 return true; 62 return true;
62 } 63 }
63 64
64 PanelManager::PanelManager() 65 PanelManager::PanelManager()
65 : panel_mouse_watcher_(PanelMouseWatcher::Create()), 66 : panel_mouse_watcher_(PanelMouseWatcher::Create()),
66 auto_sizing_enabled_(true), 67 auto_sizing_enabled_(true),
67 is_full_screen_(false) { 68 is_full_screen_(false),
69 is_processing_overflow_(false) {
68 detached_strip_.reset(new DetachedPanelStrip(this)); 70 detached_strip_.reset(new DetachedPanelStrip(this));
69 docked_strip_.reset(new DockedPanelStrip(this)); 71 docked_strip_.reset(new DockedPanelStrip(this));
70 overflow_strip_.reset(new OverflowPanelStrip(this)); 72 overflow_strip_.reset(new OverflowPanelStrip(this));
71 drag_controller_.reset(new PanelDragController()); 73 drag_controller_.reset(new PanelDragController());
72 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); 74 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this);
73 OnDisplayChanged(); 75 OnDisplayChanged();
74 } 76 }
75 77
76 PanelManager::~PanelManager() { 78 PanelManager::~PanelManager() {
77 } 79 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 112
111 gfx::Rect overflow_area(adjusted_work_area_); 113 gfx::Rect overflow_area(adjusted_work_area_);
112 overflow_area.set_width(kOverflowStripThickness); 114 overflow_area.set_width(kOverflowStripThickness);
113 overflow_strip_->SetDisplayArea(overflow_area); 115 overflow_strip_->SetDisplayArea(overflow_area);
114 } 116 }
115 117
116 Panel* PanelManager::CreatePanel(Browser* browser) { 118 Panel* PanelManager::CreatePanel(Browser* browser) {
117 int width = browser->override_bounds().width(); 119 int width = browser->override_bounds().width();
118 int height = browser->override_bounds().height(); 120 int height = browser->override_bounds().height();
119 Panel* panel = new Panel(browser, gfx::Size(width, height)); 121 Panel* panel = new Panel(browser, gfx::Size(width, height));
120 panel->MoveToStrip(docked_strip_.get()); 122 docked_strip_->AddPanel(panel);
121 123
122 content::NotificationService::current()->Notify( 124 content::NotificationService::current()->Notify(
123 chrome::NOTIFICATION_PANEL_ADDED, 125 chrome::NOTIFICATION_PANEL_ADDED,
124 content::Source<Panel>(panel), 126 content::Source<Panel>(panel),
125 content::NotificationService::NoDetails()); 127 content::NotificationService::NoDetails());
126 128
127 if (num_panels() == 1) { 129 if (num_panels() == 1) {
128 full_screen_mode_timer_.Start(FROM_HERE, 130 full_screen_mode_timer_.Start(FROM_HERE,
129 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), 131 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs),
130 this, &PanelManager::CheckFullScreenMode); 132 this, &PanelManager::CheckFullScreenMode);
131 } 133 }
132 134
133 return panel; 135 return panel;
134 } 136 }
135 137
136 int PanelManager::StartingRightPosition() const { 138 int PanelManager::StartingRightPosition() const {
137 return docked_strip_->StartingRightPosition(); 139 return docked_strip_->StartingRightPosition();
138 } 140 }
139 141
140 void PanelManager::CheckFullScreenMode() { 142 void PanelManager::CheckFullScreenMode() {
141 bool is_full_screen_new = IsFullScreenMode(); 143 bool is_full_screen_new = IsFullScreenMode();
142 if (is_full_screen_ == is_full_screen_new) 144 if (is_full_screen_ == is_full_screen_new)
143 return; 145 return;
144 is_full_screen_ = is_full_screen_new; 146 is_full_screen_ = is_full_screen_new;
145 docked_strip_->OnFullScreenModeChanged(is_full_screen_); 147 docked_strip_->OnFullScreenModeChanged(is_full_screen_);
146 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); 148 overflow_strip_->OnFullScreenModeChanged(is_full_screen_);
147 } 149 }
148 150
149 void PanelManager::OnPanelClosed(Panel* panel) { 151 void PanelManager::OnPanelClosed(Panel* panel) {
150 if (num_panels() == 0) 152 if (num_panels() == 1)
151 full_screen_mode_timer_.Stop(); 153 full_screen_mode_timer_.Stop();
152 154
153 drag_controller_->OnPanelClosed(panel); 155 drag_controller_->OnPanelClosed(panel);
156 panel->panel_strip()->RemovePanel(panel);
154 157
155 content::NotificationService::current()->Notify( 158 content::NotificationService::current()->Notify(
156 chrome::NOTIFICATION_PANEL_CLOSED, 159 chrome::NOTIFICATION_PANEL_CLOSED,
157 content::Source<Panel>(panel), 160 content::Source<Panel>(panel),
158 content::NotificationService::NoDetails()); 161 content::NotificationService::NoDetails());
159 } 162 }
160 163
161 void PanelManager::StartDragging(Panel* panel) { 164 void PanelManager::StartDragging(Panel* panel) {
162 drag_controller_->StartDragging(panel); 165 drag_controller_->StartDragging(panel);
163 } 166 }
(...skipping 21 matching lines...) Expand all
185 188
186 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { 189 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) {
187 // Explicit resizing is not allowed for auto-resizable panels for now. 190 // Explicit resizing is not allowed for auto-resizable panels for now.
188 // http://crbug.com/109343 191 // http://crbug.com/109343
189 if (panel->auto_resizable()) 192 if (panel->auto_resizable())
190 return; 193 return;
191 194
192 docked_strip_->ResizePanelWindow(panel, new_size); 195 docked_strip_->ResizePanelWindow(panel, new_size);
193 } 196 }
194 197
198 void PanelManager::MovePanelToStrip(Panel* panel,
199 PanelStrip::Type new_layout) {
200 DCHECK(panel);
201 PanelStrip* current_strip = panel->panel_strip();
202 DCHECK(current_strip);
203 DCHECK_NE(current_strip->type(), new_layout);
204 current_strip->RemovePanel(panel);
205
206 PanelStrip* target_strip = NULL;
207 switch (new_layout) {
208 case PanelStrip::DETACHED:
209 target_strip = detached_strip_.get();
210 break;
211 case PanelStrip::DOCKED:
212 target_strip = docked_strip_.get();
213 break;
214 case PanelStrip::IN_OVERFLOW:
215 target_strip = overflow_strip_.get();
216 break;
217 default:
218 NOTREACHED();
219 }
220
221 target_strip->AddPanel(panel);
222
223 content::NotificationService::current()->Notify(
224 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE,
225 content::Source<Panel>(panel),
226 content::NotificationService::NoDetails());
227 }
228
229 void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) {
230 AutoReset<bool> processing_overflow(&is_processing_overflow_, true);
231 // Move panels to overflow in reverse to maintain their order.
232 Panel* bumped_panel;
233 while ((bumped_panel = docked_strip_->last_panel())) {
234 MovePanelToStrip(bumped_panel, PanelStrip::IN_OVERFLOW);
235 if (bumped_panel == last_panel_to_move)
236 break;
237 }
238 DCHECK(!docked_strip_->panels().empty());
239 }
240
241 void PanelManager::MovePanelsOutOfOverflowIfCanFit() {
242 if (is_processing_overflow_)
243 return;
244
245 Panel* overflow_panel;
246 while ((overflow_panel = overflow_strip_->first_panel()) &&
247 docked_strip_->CanFitPanel(overflow_panel))
248 MovePanelToStrip(overflow_panel, PanelStrip::DOCKED);
249 }
250
195 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { 251 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
196 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); 252 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y);
197 } 253 }
198 254
199 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { 255 void PanelManager::BringUpOrDownTitlebars(bool bring_up) {
200 docked_strip_->BringUpOrDownTitlebars(bring_up); 256 docked_strip_->BringUpOrDownTitlebars(bring_up);
201 } 257 }
202 258
203 void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { 259 void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() {
204 // Note that we do not care about the desktop bar aligned to the top edge 260 // Note that we do not care about the desktop bar aligned to the top edge
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return panels; 329 return panels;
274 } 330 }
275 331
276 int PanelManager::overflow_strip_width() const { 332 int PanelManager::overflow_strip_width() const {
277 return kOverflowStripThickness; 333 return kOverflowStripThickness;
278 } 334 }
279 335
280 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { 336 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) {
281 panel_mouse_watcher_.reset(watcher); 337 panel_mouse_watcher_.reset(watcher);
282 } 338 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_manager.h ('k') | chrome/browser/ui/panels/panel_overflow_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698