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

Unified Diff: chrome/browser/ui/panels/panel_manager.cc

Issue 8341098: Mac: Added a delay before panels go to minimized state from title-only state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cr feedback Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
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..eaa2b0432b9887ab4c937e68f9bcdddc7d00a94c 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -32,11 +32,21 @@ 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;
+#else
+const int kMillisecondsBeforeCollapsingFromTitleonlyState = 0;
+#endif
+
// Single instance of PanelManager.
scoped_refptr<PanelManager> panel_manager_instance;
} // namespace
// static
+int PanelManager::s_last_task_index = 0;
+
+// static
PanelManager* PanelManager::GetInstance() {
if (!panel_manager_instance.get())
panel_manager_instance = new PanelManager();
@@ -49,6 +59,7 @@ PanelManager::PanelManager()
dragging_panel_index_(kInvalidPanelIndex),
dragging_panel_original_x_(0),
delayed_titlebar_action_(NO_ACTION),
+ reduced_delays_for_testing_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
auto_sizing_enabled_(true),
mouse_watching_disabled_(false) {
@@ -392,6 +403,7 @@ bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
}
void PanelManager::BringUpOrDownTitlebars(bool bring_up) {
+ int task_delay = 0;
jianli 2011/10/28 21:31:33 Please add an empty line here. Also, task_delay_ti
Dmitry Titov 2011/10/29 00:04:56 made it task_delay_milliseconds.
// 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 +412,60 @@ 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 = 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) {
+ if (task_delay < kMillisecondsBeforeCollapsingFromTitleonlyState)
+ task_delay = kMillisecondsBeforeCollapsingFromTitleonlyState;
+ }
+
+ // OnAutoHidingDesktopBarVisibilityChanged will handle this.
+ delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN;
+ if (reduced_delays_for_testing_)
jianli 2011/10/28 21:31:33 This sounds more like removed_delays_for_testing_
Dmitry Titov 2011/10/29 00:04:56 renamed to remove_delays_for_testing_
+ task_delay = 0;
+
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &PanelManager::DelayedBringUpOrDownTitlebarsCheck,
+ ++s_last_task_index),
jianli 2011/10/28 21:31:33 I think we can avoid using this static variable in
Dmitry Titov 2011/10/29 00:04:56 Replaced by using Cancel() on a task. Keep the poi
+ task_delay);
}
-void PanelManager::DelayedBringUpOrDownTitlebarsCheck() {
+void PanelManager::DelayedBringUpOrDownTitlebarsCheck(int task_index) {
+ // Task was already processed or cancelled - bail out.
if (delayed_titlebar_action_ == NO_ACTION)
return;
- DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP);
+ // In case we posted multiple tasks because user was moving mouse back and
+ // forth, ignore all but the last one.
+ if (task_index < s_last_task_index)
+ return;
+ DCHECK(task_index == s_last_task_index);
+
+ bool need_to_bring_titlebars_up = (delayed_titlebar_action_ == BRING_UP);
jianli 2011/10/28 21:31:33 need_to_bring_titlebars_up => need_to_bring_up_tit
Dmitry Titov 2011/10/29 00:04:56 Done
+
+ // We are going to process the task one way or another after this point.
jianli 2011/10/28 21:31:33 This comment is kind of confusing. Why not removin
Dmitry Titov 2011/10/29 00:04:56 Done.
delayed_titlebar_action_ = NO_ACTION;
+
+ // Check if the action is still needed based on mouse position. In case the
+ // mouse moved and does not call for the titlebars change, cancel.
jianli 2011/10/28 21:31:33 Comment here is a bit hard to understand. How abou
Dmitry Titov 2011/10/29 00:04:56 Done.
+ if (are_titlebars_up_ != need_to_bring_titlebars_up)
+ return;
+
+ DoBringUpOrDownTitlebars(need_to_bring_titlebars_up);
}
void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) {

Powered by Google App Engine
This is Rietveld 408576698