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; | |
| 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 |
| 47 int PanelManager::s_last_task_index = 0; | |
| 48 | |
| 49 // static | |
| 40 PanelManager* PanelManager::GetInstance() { | 50 PanelManager* PanelManager::GetInstance() { |
| 41 if (!panel_manager_instance.get()) | 51 if (!panel_manager_instance.get()) |
| 42 panel_manager_instance = new PanelManager(); | 52 panel_manager_instance = new PanelManager(); |
| 43 return panel_manager_instance.get(); | 53 return panel_manager_instance.get(); |
| 44 } | 54 } |
| 45 | 55 |
| 46 PanelManager::PanelManager() | 56 PanelManager::PanelManager() |
| 47 : minimized_panel_count_(0), | 57 : minimized_panel_count_(0), |
| 48 are_titlebars_up_(false), | 58 are_titlebars_up_(false), |
| 49 dragging_panel_index_(kInvalidPanelIndex), | 59 dragging_panel_index_(kInvalidPanelIndex), |
| 50 dragging_panel_original_x_(0), | 60 dragging_panel_original_x_(0), |
| 51 delayed_titlebar_action_(NO_ACTION), | 61 delayed_titlebar_action_(NO_ACTION), |
| 62 reduced_delays_for_testing_(false), | |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 63 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 53 auto_sizing_enabled_(true), | 64 auto_sizing_enabled_(true), |
| 54 mouse_watching_disabled_(false) { | 65 mouse_watching_disabled_(false) { |
| 55 panel_mouse_watcher_.reset(PanelMouseWatcher::Create(this)); | 66 panel_mouse_watcher_.reset(PanelMouseWatcher::Create(this)); |
| 56 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | 67 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
| 57 OnDisplayChanged(); | 68 OnDisplayChanged(); |
| 58 } | 69 } |
| 59 | 70 |
| 60 PanelManager::~PanelManager() { | 71 PanelManager::~PanelManager() { |
| 61 DCHECK(panels_.empty()); | 72 DCHECK(panels_.empty()); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 | 396 |
| 386 for (Panels::const_iterator iter = panels_.begin(); | 397 for (Panels::const_iterator iter = panels_.begin(); |
| 387 iter != panels_.end(); ++iter) { | 398 iter != panels_.end(); ++iter) { |
| 388 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) | 399 if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y)) |
| 389 return true; | 400 return true; |
| 390 } | 401 } |
| 391 return false; | 402 return false; |
| 392 } | 403 } |
| 393 | 404 |
| 394 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 405 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
| 406 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.
| |
| 395 // If the auto-hiding bottom bar exists, delay the action until the bottom | 407 // 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 | 408 // 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. | 409 // titlebar to move at the same time but with different speeds. |
| 398 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { | 410 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
| 399 AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> | 411 AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> |
| 400 GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); | 412 GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
| 401 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE | 413 if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE |
| 402 : AutoHidingDesktopBar::HIDDEN)) { | 414 : 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 | 415 // 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. | 416 // 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 | 417 // 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 | 418 // the bottom bar visibility change notification within a certain period |
| 410 // of time. | 419 // of time. |
| 411 MessageLoop::current()->PostDelayedTask( | 420 task_delay = kMaxMillisecondsWaitForBottomBarVisibilityChange; |
| 412 FROM_HERE, | |
| 413 method_factory_.NewRunnableMethod( | |
| 414 &PanelManager::DelayedBringUpOrDownTitlebarsCheck), | |
| 415 kMaxMillisecondsWaitForBottomBarVisibilityChange); | |
| 416 | |
| 417 return; | |
| 418 } | 421 } |
| 419 } | 422 } |
| 420 | 423 |
| 421 DoBringUpOrDownTitlebars(bring_up); | 424 // On some OSes, the interaction with native Taskbars/Docks may be improved |
| 425 // if the panels do not go back to minimized state too fast. For example, | |
| 426 // it makes it possible to hit the titlebar on OSX if Dock has Magnifying | |
| 427 // enabled - the panels stay up for a while after Dock magnification effect | |
| 428 // stops covering the panels. | |
| 429 if (!bring_up) { | |
| 430 if (task_delay < kMillisecondsBeforeCollapsingFromTitleonlyState) | |
| 431 task_delay = kMillisecondsBeforeCollapsingFromTitleonlyState; | |
| 432 } | |
| 433 | |
| 434 // OnAutoHidingDesktopBarVisibilityChanged will handle this. | |
| 435 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; | |
| 436 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_
| |
| 437 task_delay = 0; | |
| 438 | |
| 439 MessageLoop::current()->PostDelayedTask( | |
| 440 FROM_HERE, | |
| 441 method_factory_.NewRunnableMethod( | |
| 442 &PanelManager::DelayedBringUpOrDownTitlebarsCheck, | |
| 443 ++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
| |
| 444 task_delay); | |
| 422 } | 445 } |
| 423 | 446 |
| 424 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { | 447 void PanelManager::DelayedBringUpOrDownTitlebarsCheck(int task_index) { |
| 448 // Task was already processed or cancelled - bail out. | |
| 425 if (delayed_titlebar_action_ == NO_ACTION) | 449 if (delayed_titlebar_action_ == NO_ACTION) |
| 426 return; | 450 return; |
| 427 | 451 |
| 428 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); | 452 // In case we posted multiple tasks because user was moving mouse back and |
| 453 // forth, ignore all but the last one. | |
| 454 if (task_index < s_last_task_index) | |
| 455 return; | |
| 456 DCHECK(task_index == s_last_task_index); | |
| 457 | |
| 458 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
| |
| 459 | |
| 460 // 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.
| |
| 429 delayed_titlebar_action_ = NO_ACTION; | 461 delayed_titlebar_action_ = NO_ACTION; |
| 462 | |
| 463 // Check if the action is still needed based on mouse position. In case the | |
| 464 // 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.
| |
| 465 if (are_titlebars_up_ != need_to_bring_titlebars_up) | |
| 466 return; | |
| 467 | |
| 468 DoBringUpOrDownTitlebars(need_to_bring_titlebars_up); | |
| 430 } | 469 } |
| 431 | 470 |
| 432 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { | 471 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |
| 433 for (Panels::const_iterator iter = panels_.begin(); | 472 for (Panels::const_iterator iter = panels_.begin(); |
| 434 iter != panels_.end(); ++iter) { | 473 iter != panels_.end(); ++iter) { |
| 435 Panel* panel = *iter; | 474 Panel* panel = *iter; |
| 436 | 475 |
| 437 // Skip any panel that is drawing the attention. | 476 // Skip any panel that is drawing the attention. |
| 438 if (panel->IsDrawingAttention()) | 477 if (panel->IsDrawingAttention()) |
| 439 continue; | 478 continue; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // Start from the bottom to avoid reshuffling. | 591 // Start from the bottom to avoid reshuffling. |
| 553 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 592 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
| 554 iter != panels_copy.rend(); ++iter) | 593 iter != panels_copy.rend(); ++iter) |
| 555 (*iter)->Close(); | 594 (*iter)->Close(); |
| 556 } | 595 } |
| 557 | 596 |
| 558 bool PanelManager::is_dragging_panel() const { | 597 bool PanelManager::is_dragging_panel() const { |
| 559 return dragging_panel_index_ != kInvalidPanelIndex; | 598 return dragging_panel_index_ != kInvalidPanelIndex; |
| 560 } | 599 } |
| 561 | 600 |
| OLD | NEW |