Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_manager.cc |
| diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc |
| index 5bb2bc8d0dc8b9280c3408159ef4e5e4dda75585..583295c7ff7dbf343a6c45fe9d968c503a8b136c 100644 |
| --- a/chrome/browser/ui/panels/panel_manager.cc |
| +++ b/chrome/browser/ui/panels/panel_manager.cc |
| @@ -32,6 +32,13 @@ const double kPanelMaxHeightFactor = 0.5; |
| // After the time expires, we bring up/down the titlebars as planned. |
| const int kMaxMillisecondsWaitForBottomBarVisibilityChange = 1000; |
| +// See usage below. |
| +#if defined(OS_MACOSX) |
| +const int kMillisecondsBeforeCollapsingFromTitleonlyState = 3000; |
|
jennb
2011/10/29 00:16:51
TitleOnly ?
Dmitry Titov
2011/10/29 00:41:58
Done.
|
| +#else |
| +const int kMillisecondsBeforeCollapsingFromTitleonlyState = 0; |
| +#endif |
| + |
| // Single instance of PanelManager. |
| scoped_refptr<PanelManager> panel_manager_instance; |
| } // namespace |
| @@ -49,6 +56,8 @@ PanelManager::PanelManager() |
| dragging_panel_index_(kInvalidPanelIndex), |
| dragging_panel_original_x_(0), |
| delayed_titlebar_action_(NO_ACTION), |
| + remove_delays_for_testing_(false), |
| + bring_up_down_task_(NULL), |
| ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| auto_sizing_enabled_(true), |
| mouse_watching_disabled_(false) { |
| @@ -61,6 +70,10 @@ PanelManager::~PanelManager() { |
| DCHECK(panels_.empty()); |
| DCHECK(panels_pending_to_remove_.empty()); |
| DCHECK_EQ(0, minimized_panel_count_); |
| + if (bring_up_down_task_) { |
| + bring_up_down_task_->Cancel(); |
| + bring_up_down_task_ = NULL; |
| + } |
| } |
| void PanelManager::OnDisplayChanged() { |
| @@ -392,6 +405,8 @@ bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
| } |
| void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
| + int task_delay_milliseconds = 0; |
| + |
| // If the auto-hiding bottom bar exists, delay the action until the bottom |
| // bar is fully visible or hidden. We do not want both bottom bar and panel |
| // titlebar to move at the same time but with different speeds. |
| @@ -400,33 +415,59 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
| GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
| if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE |
| : AutoHidingDesktopBar::HIDDEN)) { |
| - // OnAutoHidingDesktopBarVisibilityChanged will handle this. |
| - delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; |
| - |
| // Occasionally some system, like Windows, might not bring up or down the |
| // bottom bar when the mouse enters or leaves the bottom screen area. |
| // Thus, we schedule a delayed task to do the work if we do not receive |
| // the bottom bar visibility change notification within a certain period |
| // of time. |
| - MessageLoop::current()->PostDelayedTask( |
| - FROM_HERE, |
| - method_factory_.NewRunnableMethod( |
| - &PanelManager::DelayedBringUpOrDownTitlebarsCheck), |
| - kMaxMillisecondsWaitForBottomBarVisibilityChange); |
| - |
| - return; |
| + task_delay_milliseconds = |
| + kMaxMillisecondsWaitForBottomBarVisibilityChange; |
| } |
| } |
| - DoBringUpOrDownTitlebars(bring_up); |
| + // On some OSes, the interaction with native Taskbars/Docks may be improved |
| + // if the panels do not go back to minimized state too fast. For example, |
| + // it makes it possible to hit the titlebar on OSX if Dock has Magnifying |
| + // enabled - the panels stay up for a while after Dock magnification effect |
| + // stops covering the panels. |
| + if (!bring_up && |
| + task_delay_milliseconds < kMillisecondsBeforeCollapsingFromTitleonlyState) |
| + 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
|
| + |
| + // OnAutoHidingDesktopBarVisibilityChanged will handle this. |
| + delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; |
| + if (remove_delays_for_testing_) |
| + task_delay_milliseconds = 0; |
| + |
| + 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.
|
| + bring_up_down_task_->Cancel(); |
| + |
| + 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
|
| + this, &PanelManager::DelayedBringUpOrDownTitlebarsCheck); |
| + |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + bring_up_down_task_, |
| + task_delay_milliseconds); |
| } |
| void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { |
| + bring_up_down_task_ = NULL; |
| + |
| + // Task was already processed or cancelled - bail out. |
| if (delayed_titlebar_action_ == NO_ACTION) |
| return; |
| - DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); |
| + bool need_to_bring_up_titlebars = (delayed_titlebar_action_ == BRING_UP); |
| + |
| delayed_titlebar_action_ = NO_ACTION; |
| + |
| + // Check if the action is still needed based on the latest mouse position. The |
| + // user could move the mouse into the tracking area and then quickly move it |
| + // out of the area. In case of this, cancel the action. |
| + if (are_titlebars_up_ != need_to_bring_up_titlebars) |
| + return; |
| + |
| + DoBringUpOrDownTitlebars(need_to_bring_up_titlebars); |
| } |
| void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |