Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 // area. | 25 // area. |
| 26 const double kPanelMaxWidthFactor = 1.0; | 26 const double kPanelMaxWidthFactor = 1.0; |
| 27 const double kPanelMaxHeightFactor = 0.5; | 27 const double kPanelMaxHeightFactor = 0.5; |
| 28 | 28 |
| 29 // Occasionally some system, like Windows, might not bring up or down the bottom | 29 // Occasionally some system, like Windows, might not bring up or down the bottom |
| 30 // bar when the mouse enters or leaves the bottom screen area. This is the | 30 // bar when the mouse enters or leaves the bottom screen area. This is the |
| 31 // maximum time we will wait for the bottom bar visibility change notification. | 31 // maximum time we will wait for the bottom bar visibility change notification. |
| 32 // After the time expires, we bring up/down the titlebars as planned. | 32 // After the time expires, we bring up/down the titlebars as planned. |
| 33 const int kMaxMillisecondsWaitForBottomBarVisibilityChange = 1000; | 33 const int kMaxMillisecondsWaitForBottomBarVisibilityChange = 1000; |
| 34 | 34 |
| 35 // See usage below. | |
| 36 #if defined(OS_MACOSX) | |
| 37 const int kMillisecondsBeforeCollapsingFromTitleonlyState = 3000; | |
|
jennb
2011/10/29 00:16:51
TitleOnly ?
Dmitry Titov
2011/10/29 00:41:58
Done.
| |
| 38 #else | |
| 39 const int kMillisecondsBeforeCollapsingFromTitleonlyState = 0; | |
| 40 #endif | |
| 41 | |
| 35 // Single instance of PanelManager. | 42 // Single instance of PanelManager. |
| 36 scoped_refptr<PanelManager> panel_manager_instance; | 43 scoped_refptr<PanelManager> panel_manager_instance; |
| 37 } // namespace | 44 } // namespace |
| 38 | 45 |
| 39 // static | 46 // static |
| 40 PanelManager* PanelManager::GetInstance() { | 47 PanelManager* PanelManager::GetInstance() { |
| 41 if (!panel_manager_instance.get()) | 48 if (!panel_manager_instance.get()) |
| 42 panel_manager_instance = new PanelManager(); | 49 panel_manager_instance = new PanelManager(); |
| 43 return panel_manager_instance.get(); | 50 return panel_manager_instance.get(); |
| 44 } | 51 } |
| 45 | 52 |
| 46 PanelManager::PanelManager() | 53 PanelManager::PanelManager() |
| 47 : minimized_panel_count_(0), | 54 : minimized_panel_count_(0), |
| 48 are_titlebars_up_(false), | 55 are_titlebars_up_(false), |
| 49 dragging_panel_index_(kInvalidPanelIndex), | 56 dragging_panel_index_(kInvalidPanelIndex), |
| 50 dragging_panel_original_x_(0), | 57 dragging_panel_original_x_(0), |
| 51 delayed_titlebar_action_(NO_ACTION), | 58 delayed_titlebar_action_(NO_ACTION), |
| 59 remove_delays_for_testing_(false), | |
| 60 bring_up_down_task_(NULL), | |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 61 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 53 auto_sizing_enabled_(true), | 62 auto_sizing_enabled_(true), |
| 54 mouse_watching_disabled_(false) { | 63 mouse_watching_disabled_(false) { |
| 55 panel_mouse_watcher_.reset(PanelMouseWatcher::Create(this)); | 64 panel_mouse_watcher_.reset(PanelMouseWatcher::Create(this)); |
| 56 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | 65 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
| 57 OnDisplayChanged(); | 66 OnDisplayChanged(); |
| 58 } | 67 } |
| 59 | 68 |
| 60 PanelManager::~PanelManager() { | 69 PanelManager::~PanelManager() { |
| 61 DCHECK(panels_.empty()); | 70 DCHECK(panels_.empty()); |
| 62 DCHECK(panels_pending_to_remove_.empty()); | 71 DCHECK(panels_pending_to_remove_.empty()); |
| 63 DCHECK_EQ(0, minimized_panel_count_); | 72 DCHECK_EQ(0, minimized_panel_count_); |
| 73 if (bring_up_down_task_) { | |
| 74 bring_up_down_task_->Cancel(); | |
| 75 bring_up_down_task_ = NULL; | |
| 76 } | |
| 64 } | 77 } |
| 65 | 78 |
| 66 void PanelManager::OnDisplayChanged() { | 79 void PanelManager::OnDisplayChanged() { |
| 67 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( | 80 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( |
| 68 WindowSizer::CreateDefaultMonitorInfoProvider()); | 81 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 69 SetWorkArea(info_provider->GetPrimaryMonitorWorkArea()); | 82 SetWorkArea(info_provider->GetPrimaryMonitorWorkArea()); |
| 70 } | 83 } |
| 71 | 84 |
| 72 void PanelManager::SetWorkArea(const gfx::Rect& work_area) { | 85 void PanelManager::SetWorkArea(const gfx::Rect& work_area) { |
| 73 if (work_area == work_area_) | 86 if (work_area == work_area_) |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 | 398 |
| 386 for (Panels::const_iterator iter = panels_.begin(); | 399 for (Panels::const_iterator iter = panels_.begin(); |
| 387 iter != panels_.end(); ++iter) { | 400 iter != panels_.end(); ++iter) { |
| 388 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) | 401 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) |
| 389 return true; | 402 return true; |
| 390 } | 403 } |
| 391 return false; | 404 return false; |
| 392 } | 405 } |
| 393 | 406 |
| 394 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 407 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
| 408 int task_delay_milliseconds = 0; | |
| 409 | |
| 395 // If the auto-hiding bottom bar exists, delay the action until the bottom | 410 // If the auto-hiding bottom bar exists, delay the action until the bottom |
| 396 // bar is fully visible or hidden. We do not want both bottom bar and panel | 411 // bar is fully visible or hidden. We do not want both bottom bar and panel |
| 397 // titlebar to move at the same time but with different speeds. | 412 // titlebar to move at the same time but with different speeds. |
| 398 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { | 413 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
| 399 AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> | 414 AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> |
| 400 GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); | 415 GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
| 401 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE | 416 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE |
| 402 : AutoHidingDesktopBar::HIDDEN)) { | 417 : AutoHidingDesktopBar::HIDDEN)) { |
| 403 // OnAutoHidingDesktopBarVisibilityChanged will handle this. | |
| 404 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; | |
| 405 | |
| 406 // Occasionally some system, like Windows, might not bring up or down the | 418 // Occasionally some system, like Windows, might not bring up or down the |
| 407 // bottom bar when the mouse enters or leaves the bottom screen area. | 419 // bottom bar when the mouse enters or leaves the bottom screen area. |
| 408 // Thus, we schedule a delayed task to do the work if we do not receive | 420 // Thus, we schedule a delayed task to do the work if we do not receive |
| 409 // the bottom bar visibility change notification within a certain period | 421 // the bottom bar visibility change notification within a certain period |
| 410 // of time. | 422 // of time. |
| 411 MessageLoop::current()->PostDelayedTask( | 423 task_delay_milliseconds = |
| 412 FROM_HERE, | 424 kMaxMillisecondsWaitForBottomBarVisibilityChange; |
| 413 method_factory_.NewRunnableMethod( | |
| 414 &PanelManager::DelayedBringUpOrDownTitlebarsCheck), | |
| 415 kMaxMillisecondsWaitForBottomBarVisibilityChange); | |
| 416 | |
| 417 return; | |
| 418 } | 425 } |
| 419 } | 426 } |
| 420 | 427 |
| 421 DoBringUpOrDownTitlebars(bring_up); | 428 // On some OSes, the interaction with native Taskbars/Docks may be improved |
| 429 // if the panels do not go back to minimized state too fast. For example, | |
| 430 // it makes it possible to hit the titlebar on OSX if Dock has Magnifying | |
| 431 // enabled - the panels stay up for a while after Dock magnification effect | |
| 432 // stops covering the panels. | |
| 433 if (!bring_up && | |
| 434 task_delay_milliseconds < kMillisecondsBeforeCollapsingFromTitleonlyState) | |
| 435 task_delay_milliseconds = kMillisecondsBeforeCollapsingFromTitleonlyState; | |
|
jennb
2011/10/29 00:16:51
Should this be += in case we also need to wait for
Dmitry Titov
2011/10/29 00:41:58
Not sure (there is no TitleonlyStata delay for Win
| |
| 436 | |
| 437 // OnAutoHidingDesktopBarVisibilityChanged will handle this. | |
| 438 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; | |
| 439 if (remove_delays_for_testing_) | |
| 440 task_delay_milliseconds = 0; | |
| 441 | |
| 442 if (bring_up_down_task_) | |
|
jianli
2011/10/29 00:19:18
Please comment why we need to cancel the task.
Dmitry Titov
2011/10/29 00:41:58
Done.
| |
| 443 bring_up_down_task_->Cancel(); | |
| 444 | |
| 445 bring_up_down_task_ = NewRunnableMethod( | |
|
jennb
2011/10/29 00:16:51
Why the change from method_factor_? Just asking fo
Dmitry Titov
2011/10/29 00:41:58
metod_factory does not give the task back. it mana
| |
| 446 this, &PanelManager::DelayedBringUpOrDownTitlebarsCheck); | |
| 447 | |
| 448 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 449 bring_up_down_task_, | |
| 450 task_delay_milliseconds); | |
| 422 } | 451 } |
| 423 | 452 |
| 424 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { | 453 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { |
| 454 bring_up_down_task_ = NULL; | |
| 455 | |
| 456 // Task was already processed or cancelled - bail out. | |
| 425 if (delayed_titlebar_action_ == NO_ACTION) | 457 if (delayed_titlebar_action_ == NO_ACTION) |
| 426 return; | 458 return; |
| 427 | 459 |
| 428 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); | 460 bool need_to_bring_up_titlebars = (delayed_titlebar_action_ == BRING_UP); |
| 461 | |
| 429 delayed_titlebar_action_ = NO_ACTION; | 462 delayed_titlebar_action_ = NO_ACTION; |
| 463 | |
| 464 // Check if the action is still needed based on the latest mouse position. The | |
| 465 // user could move the mouse into the tracking area and then quickly move it | |
| 466 // out of the area. In case of this, cancel the action. | |
| 467 if (are_titlebars_up_ != need_to_bring_up_titlebars) | |
| 468 return; | |
| 469 | |
| 470 DoBringUpOrDownTitlebars(need_to_bring_up_titlebars); | |
| 430 } | 471 } |
| 431 | 472 |
| 432 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { | 473 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |
| 433 for (Panels::const_iterator iter = panels_.begin(); | 474 for (Panels::const_iterator iter = panels_.begin(); |
| 434 iter != panels_.end(); ++iter) { | 475 iter != panels_.end(); ++iter) { |
| 435 Panel* panel = *iter; | 476 Panel* panel = *iter; |
| 436 | 477 |
| 437 // Skip any panel that is drawing the attention. | 478 // Skip any panel that is drawing the attention. |
| 438 if (panel->IsDrawingAttention()) | 479 if (panel->IsDrawingAttention()) |
| 439 continue; | 480 continue; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // Start from the bottom to avoid reshuffling. | 593 // Start from the bottom to avoid reshuffling. |
| 553 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 594 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
| 554 iter != panels_copy.rend(); ++iter) | 595 iter != panels_copy.rend(); ++iter) |
| 555 (*iter)->Close(); | 596 (*iter)->Close(); |
| 556 } | 597 } |
| 557 | 598 |
| 558 bool PanelManager::is_dragging_panel() const { | 599 bool PanelManager::is_dragging_panel() const { |
| 559 return dragging_panel_index_ != kInvalidPanelIndex; | 600 return dragging_panel_index_ != kInvalidPanelIndex; |
| 560 } | 601 } |
| 561 | 602 |
| OLD | NEW |