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

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

Issue 7646003: Support auto-hide taskbar for panels on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/window_sizer.h" 13 #include "chrome/browser/ui/window_sizer.h"
13 14
14 namespace { 15 namespace {
15 // Invalid panel index. 16 // Invalid panel index.
16 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); 17 const size_t kInvalidPanelIndex = static_cast<size_t>(-1);
17 18
18 // Minimum width and height of a panel. 19 // Minimum width and height of a panel.
19 const int kPanelMinWidthPixels = 64; 20 const int kPanelMinWidthPixels = 64;
20 const int kPanelMinHeightPixels = 24; 21 const int kPanelMinHeightPixels = 24;
21 22
22 // Default width and height of a panel. 23 // Default width and height of a panel.
23 const int kPanelDefaultWidthPixels = 240; 24 const int kPanelDefaultWidthPixels = 240;
24 const int kPanelDefaultHeightPixels = 290; 25 const int kPanelDefaultHeightPixels = 290;
25 26
26 // Maxmium width and height of a panel based on the factor of the working 27 // Maxmium width and height of a panel based on the factor of the working
27 // area. 28 // area.
28 const double kPanelMaxWidthFactor = 1.0; 29 const double kPanelMaxWidthFactor = 1.0;
29 const double kPanelMaxHeightFactor = 0.5; 30 const double kPanelMaxHeightFactor = 0.5;
30 31
31 // Horizontal spacing between two panels. 32 // Horizontal spacing between two panels.
32 const int kPanelsHorizontalSpacing = 4; 33 const int kPanelsHorizontalSpacing = 4;
33 34
35 // The delayed interval to do the check to ensure we bring up or down titlebars.
36 const int kDelayedBringUpOrDownTitlebarsCheckMs = 1000;
37
34 // Single instance of PanelManager. 38 // Single instance of PanelManager.
35 scoped_ptr<PanelManager> panel_instance; 39 scoped_refptr<PanelManager> panel_instance;
jennb 2011/08/22 21:00:16 Rename this to panel_manager_instance? Took me a
jianli 2011/08/22 23:28:10 Done.
36 } // namespace 40 } // namespace
37 41
38 // static 42 // static
39 PanelManager* PanelManager::GetInstance() { 43 PanelManager* PanelManager::GetInstance() {
40 if (!panel_instance.get()) { 44 if (!panel_instance.get()) {
41 panel_instance.reset(new PanelManager()); 45 panel_instance = new PanelManager();
46 panel_instance->Init();
42 } 47 }
43 return panel_instance.get(); 48 return panel_instance.get();
44 } 49 }
45 50
51 // static
52 void PanelManager::CreateForTesting(const gfx::Rect& work_area,
jennb 2011/08/22 21:00:16 Alternative would be to have a method to set the A
jianli 2011/08/22 23:28:10 I've tried this but it caused crash if we call Pan
53 AutoHideBottomBar* auto_hide_bottom_bar) {
54 DCHECK(!panel_instance.get());
55 panel_instance = new PanelManager();
56 panel_instance->auto_hide_bottom_bar_ = auto_hide_bottom_bar;
57 panel_instance->SetWorkArea(work_area);
58 }
59
46 PanelManager::PanelManager() 60 PanelManager::PanelManager()
47 : max_width_(0), 61 : max_width_(0),
48 max_height_(0), 62 max_height_(0),
49 min_x_(0),
50 current_x_(0), 63 current_x_(0),
51 bottom_edge_y_(0),
52 dragging_panel_index_(kInvalidPanelIndex), 64 dragging_panel_index_(kInvalidPanelIndex),
53 dragging_panel_original_x_(0) { 65 dragging_panel_original_x_(0),
54 OnDisplayChanged(); 66 delayed_titlebar_action_(NO_ACTION),
67 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
55 } 68 }
56 69
57 PanelManager::~PanelManager() { 70 PanelManager::~PanelManager() {
58 DCHECK(panels_.empty()); 71 DCHECK(panels_.empty());
59 DCHECK(panels_pending_to_remove_.empty()); 72 DCHECK(panels_pending_to_remove_.empty());
60 } 73 }
61 74
75 void PanelManager::Init() {
76 auto_hide_bottom_bar_ = AutoHideBottomBar::Create(this);
77 OnDisplayChanged();
78 }
79
62 void PanelManager::OnDisplayChanged() { 80 void PanelManager::OnDisplayChanged() {
63 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( 81 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider(
64 WindowSizer::CreateDefaultMonitorInfoProvider()); 82 WindowSizer::CreateDefaultMonitorInfoProvider());
65 SetWorkArea(info_provider->GetPrimaryMonitorWorkArea()); 83 gfx::Rect work_area = info_provider->GetPrimaryMonitorWorkArea();
84 SetWorkArea(work_area);
66 } 85 }
67 86
68 void PanelManager::SetWorkArea(const gfx::Rect& work_area) { 87 void PanelManager::SetWorkArea(const gfx::Rect& work_area) {
69 if (work_area == work_area_) 88 if (work_area == work_area_)
70 return; 89 return;
71 work_area_ = work_area; 90 work_area_ = work_area;
72 91
73 min_x_ = work_area.x(); 92 auto_hide_bottom_bar_->UpdateWorkArea(work_area);
93
74 current_x_ = work_area.right(); 94 current_x_ = work_area.right();
75 bottom_edge_y_ = work_area.bottom();
76 max_width_ = static_cast<int>(work_area.width() * kPanelMaxWidthFactor); 95 max_width_ = static_cast<int>(work_area.width() * kPanelMaxWidthFactor);
77 max_height_ = static_cast<int>(work_area.height() * kPanelMaxHeightFactor); 96 max_height_ = static_cast<int>(work_area.height() * kPanelMaxHeightFactor);
78 97
79 Rearrange(panels_.begin()); 98 Rearrange(panels_.begin());
80 } 99 }
81 100
82 void PanelManager::FindAndClosePanelOnOverflow(const Extension* extension) { 101 void PanelManager::FindAndClosePanelOnOverflow(const Extension* extension) {
83 Panel* panel_to_close = NULL; 102 Panel* panel_to_close = NULL;
84 103
85 // Try to find the left-most panel invoked from the same extension and close 104 // Try to find the left-most panel invoked from the same extension and close
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } else { 283 } else {
265 panels_[dragging_panel_index_]->SetPanelBounds( 284 panels_[dragging_panel_index_]->SetPanelBounds(
266 dragging_panel_bounds_); 285 dragging_panel_bounds_);
267 } 286 }
268 287
269 dragging_panel_index_ = kInvalidPanelIndex; 288 dragging_panel_index_ = kInvalidPanelIndex;
270 289
271 DelayedRemove(); 290 DelayedRemove();
272 } 291 }
273 292
274 bool PanelManager::ShouldBringUpTitlebarForAllMinimizedPanels( 293 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
275 int mouse_x, int mouse_y) const { 294 // We should always bring up the title-bar if the mouse is over the auto-hide
295 // task-bar that becomes visible.
296 if (auto_hide_bottom_bar_->Exists() &&
297 auto_hide_bottom_bar_->GetVisibility() == AutoHideBottomBar::VISIBLE &&
298 mouse_y >= work_area_.bottom() - auto_hide_bottom_bar_->GetHeight())
299 return true;
300
276 for (Panels::const_iterator iter = panels_.begin(); 301 for (Panels::const_iterator iter = panels_.begin();
277 iter != panels_.end(); ++iter) { 302 iter != panels_.end(); ++iter) {
278 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) 303 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y))
279 return true; 304 return true;
280 } 305 }
281 return false; 306 return false;
282 } 307 }
283 308
284 void PanelManager::BringUpOrDownTitlebarForAllMinimizedPanels(bool bring_up) { 309 void PanelManager::BringUpOrDownTitlebars(bool bring_up) {
310 // If the auto-hide bottom bar exists, delay the action until the bottom
311 // bar is fully visible or hidden. We do not want both bottom bar and panel
312 // titlebar to move at the same time but with different speeds.
313 if (auto_hide_bottom_bar_->Exists()) {
314 AutoHideBottomBar::Visibility visibility =
315 auto_hide_bottom_bar_->GetVisibility();
316 if (visibility != (bring_up ? AutoHideBottomBar::VISIBLE
317 : AutoHideBottomBar::HIDDEN)) {
318 // OnAutoHideBottomBarVisibilityChanged will handle this.
319 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN;
320
321 // Sometimes, the bottom bar does not appear or hide promptly. Schedule
322 // a delayed task to make sure our delayed action is performed.
323 MessageLoop::current()->PostDelayedTask(
324 FROM_HERE,
325 method_factory_.NewRunnableMethod(
326 &PanelManager::DelayedBringUpOrDownTitlebarsCheck),
327 kDelayedBringUpOrDownTitlebarsCheckMs);
328
329 return;
330 }
331 }
332
333 DoBringUpOrDownTitlebars(bring_up);
334 }
335
336 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() {
337 switch (delayed_titlebar_action_) {
338 case NO_ACTION:
339 break;
340 case BRING_UP:
341 delayed_titlebar_action_ = NO_ACTION;
342 DoBringUpOrDownTitlebars(true);
343 break;
344 case BRING_DOWN:
345 delayed_titlebar_action_ = NO_ACTION;
346 DoBringUpOrDownTitlebars(false);
347 break;
348 default:
349 NOTREACHED();
350 break;
351 }
352 }
353
354 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) {
285 for (Panels::const_iterator iter = panels_.begin(); 355 for (Panels::const_iterator iter = panels_.begin();
286 iter != panels_.end(); ++iter) { 356 iter != panels_.end(); ++iter) {
287 Panel* panel = *iter; 357 Panel* panel = *iter;
288 358
289 // Skip any panel that is drawing the attention. 359 // Skip any panel that is drawing the attention.
290 if (panel->IsDrawingAttention()) 360 if (panel->IsDrawingAttention())
291 continue; 361 continue;
292 362
293 if (bring_up) { 363 if (bring_up) {
294 if (panel->expansion_state() == Panel::MINIMIZED) 364 if (panel->expansion_state() == Panel::MINIMIZED)
295 panel->SetExpansionState(Panel::TITLE_ONLY); 365 panel->SetExpansionState(Panel::TITLE_ONLY);
296 } else { 366 } else {
297 if (panel->expansion_state() == Panel::TITLE_ONLY) 367 if (panel->expansion_state() == Panel::TITLE_ONLY)
298 panel->SetExpansionState(Panel::MINIMIZED); 368 panel->SetExpansionState(Panel::MINIMIZED);
299 } 369 }
300 } 370 }
301 } 371 }
302 372
373 int PanelManager::GetBottomPositionForExpansionState(
374 Panel::ExpansionState expansion_state) const {
375 int bottom = work_area_.bottom();
376 if (expansion_state != Panel::MINIMIZED)
377 bottom -= auto_hide_bottom_bar_->GetHeight();
378 return bottom;
379 }
380
381 void PanelManager::OnAutoHideBottomBarVisibilityChanged(
382 AutoHideBottomBar::Visibility visibility) {
383 switch (delayed_titlebar_action_) {
384 case NO_ACTION:
385 break;
386 case BRING_UP:
387 if (visibility == AutoHideBottomBar::VISIBLE) {
388 delayed_titlebar_action_ = NO_ACTION;
389 DoBringUpOrDownTitlebars(true);
390 }
391 break;
392 case BRING_DOWN:
393 if (visibility == AutoHideBottomBar::HIDDEN) {
394 delayed_titlebar_action_ = NO_ACTION;
395 DoBringUpOrDownTitlebars(false);
396 }
397 break;
398 default:
399 NOTREACHED();
400 break;
401 }
402 }
403
404 void PanelManager::OnAutoHideBottomBarHeightChanged(int height) {
405 current_x_ = work_area_.right();
406 Rearrange(panels_.begin());
407 }
408
303 void PanelManager::Rearrange(Panels::iterator iter_to_start) { 409 void PanelManager::Rearrange(Panels::iterator iter_to_start) {
304 if (iter_to_start == panels_.end()) 410 if (iter_to_start == panels_.end())
305 return; 411 return;
306 412
307 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { 413 for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) {
308 gfx::Rect new_bounds((*iter)->GetBounds()); 414 gfx::Rect new_bounds((*iter)->GetBounds());
309 ComputeBoundsForNextPanel(&new_bounds, false); 415 ComputeBoundsForNextPanel(&new_bounds, false);
310 if (new_bounds != (*iter)->GetBounds()) 416 if (new_bounds != (*iter)->GetBounds())
311 (*iter)->SetPanelBounds(new_bounds); 417 (*iter)->SetPanelBounds(new_bounds);
312 } 418 }
(...skipping 16 matching lines...) Expand all
329 else if (width > max_width_) 435 else if (width > max_width_)
330 width = max_width_; 436 width = max_width_;
331 437
332 if (height < kPanelMinHeightPixels) 438 if (height < kPanelMinHeightPixels)
333 height = kPanelMinHeightPixels; 439 height = kPanelMinHeightPixels;
334 else if (height > max_height_) 440 else if (height > max_height_)
335 height = max_height_; 441 height = max_height_;
336 } 442 }
337 443
338 int x = current_x_ - width; 444 int x = current_x_ - width;
339 int y = bottom_edge_y_ - height; 445 int y = work_area_.bottom() - auto_hide_bottom_bar_->GetHeight() - height;
340 446
341 if (x < min_x_) 447 if (x < work_area_.x())
342 return false; 448 return false;
343 449
344 current_x_ -= width + kPanelsHorizontalSpacing; 450 current_x_ -= width + kPanelsHorizontalSpacing;
345 451
346 bounds->SetRect(x, y, width, height); 452 bounds->SetRect(x, y, width, height);
347 return true; 453 return true;
348 } 454 }
349 455
350 void PanelManager::RemoveAll() { 456 void PanelManager::RemoveAll() {
351 // This should not be called when we're in the process of dragging. 457 // This should not be called when we're in the process of dragging.
352 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); 458 DCHECK(dragging_panel_index_ == kInvalidPanelIndex);
353 459
354 // Start from the bottom to avoid reshuffling. 460 // Start from the bottom to avoid reshuffling.
355 for (Panels::reverse_iterator iter = panels_.rbegin(); 461 for (Panels::reverse_iterator iter = panels_.rbegin();
356 iter != panels_.rend(); ++iter) 462 iter != panels_.rend(); ++iter)
357 (*iter)->Close(); 463 (*iter)->Close();
358 } 464 }
359 465
360 bool PanelManager::is_dragging_panel() const { 466 bool PanelManager::is_dragging_panel() const {
361 return dragging_panel_index_ != kInvalidPanelIndex; 467 return dragging_panel_index_ != kInvalidPanelIndex;
362 } 468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698