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) | |
jianli
2011/10/28 01:04:11
Extra empty space.
Dmitry Titov
2011/10/28 20:58:23
Done.
| |
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::sLastTaskIndex = 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), |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; | 414 delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN; |
405 | 415 |
406 // Occasionally some system, like Windows, might not bring up or down the | 416 // 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. | 417 // 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 | 418 // 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 | 419 // the bottom bar visibility change notification within a certain period |
410 // of time. | 420 // of time. |
411 MessageLoop::current()->PostDelayedTask( | 421 MessageLoop::current()->PostDelayedTask( |
412 FROM_HERE, | 422 FROM_HERE, |
413 method_factory_.NewRunnableMethod( | 423 method_factory_.NewRunnableMethod( |
414 &PanelManager::DelayedBringUpOrDownTitlebarsCheck), | 424 &PanelManager::DelayedBringUpOrDownTitlebarsCheck, |
425 ++sLastTaskIndex), | |
jianli
2011/10/28 01:04:11
Where do we reset sLastTaskIndex? What if increasi
Dmitry Titov
2011/10/28 20:58:23
If we post a task every time user moves the mouse
| |
415 kMaxMillisecondsWaitForBottomBarVisibilityChange); | 426 kMaxMillisecondsWaitForBottomBarVisibilityChange); |
416 | 427 |
417 return; | 428 return; |
418 } | 429 } |
419 } | 430 } |
420 | 431 |
432 // On some OSes, the interaction with native Taskbars/Docks may be improved | |
433 // if the panels are not go back to minimized state too fast. For example, | |
jianli
2011/10/28 01:04:11
are not => do not
Dmitry Titov
2011/10/28 20:58:23
Done.
| |
434 // it makes it possible to hit the titlebar on OSX if Dock has Magnifying | |
435 // enabled - the panels stay up for a while after Dock magnification effect | |
436 // stops covering the panels. | |
437 if (!bring_up) { | |
438 delayed_titlebar_action_ = BRING_DOWN; | |
439 MessageLoop::current()->PostDelayedTask( | |
jianli
2011/10/28 01:04:11
This seems to be similar to the above PostDelayed
Dmitry Titov
2011/10/28 20:58:23
Done.
| |
440 FROM_HERE, | |
441 method_factory_.NewRunnableMethod( | |
442 &PanelManager::DelayedBringUpOrDownTitlebarsCheck, | |
443 ++sLastTaskIndex), | |
444 kMillisecondsBeforeCollapsingFromTitleonlyState); | |
445 return; | |
446 } | |
447 | |
448 | |
421 DoBringUpOrDownTitlebars(bring_up); | 449 DoBringUpOrDownTitlebars(bring_up); |
422 } | 450 } |
423 | 451 |
424 void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { | 452 void PanelManager::DelayedBringUpOrDownTitlebarsCheck(int taskIndex) { |
jianli
2011/10/28 01:04:11
taskIndex => task_index
Dmitry Titov
2011/10/28 20:58:23
Done.
| |
453 // task was already processed or cancelled - bail out. | |
jianli
2011/10/28 01:04:11
task needs to be capitalized.
Dmitry Titov
2011/10/28 20:58:23
Done.
| |
425 if (delayed_titlebar_action_ == NO_ACTION) | 454 if (delayed_titlebar_action_ == NO_ACTION) |
426 return; | 455 return; |
427 | 456 |
457 // In case we posted multiple tasks because user was moving mouse back and | |
458 // forth, ignore all but the last one. | |
459 if (taskIndex < sLastTaskIndex) | |
460 return; | |
461 DCHECK(taskIndex == sLastTaskIndex); | |
462 | |
463 // We are going to process the task one way or another after this point. | |
464 delayed_titlebar_action_ = NO_ACTION; | |
465 | |
466 // Check if the action is still needed based on mouse position. In case the | |
467 // mouse moved and does not call for the titlebars change, cancel. | |
468 if (are_titlebars_up_ != (delayed_titlebar_action_ == BRING_UP)) | |
469 return; | |
470 | |
428 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); | 471 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); |
429 delayed_titlebar_action_ = NO_ACTION; | |
430 } | 472 } |
431 | 473 |
432 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { | 474 void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |
433 for (Panels::const_iterator iter = panels_.begin(); | 475 for (Panels::const_iterator iter = panels_.begin(); |
434 iter != panels_.end(); ++iter) { | 476 iter != panels_.end(); ++iter) { |
435 Panel* panel = *iter; | 477 Panel* panel = *iter; |
436 | 478 |
437 // Skip any panel that is drawing the attention. | 479 // Skip any panel that is drawing the attention. |
438 if (panel->IsDrawingAttention()) | 480 if (panel->IsDrawingAttention()) |
439 continue; | 481 continue; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 // Start from the bottom to avoid reshuffling. | 594 // Start from the bottom to avoid reshuffling. |
553 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 595 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
554 iter != panels_copy.rend(); ++iter) | 596 iter != panels_copy.rend(); ++iter) |
555 (*iter)->Close(); | 597 (*iter)->Close(); |
556 } | 598 } |
557 | 599 |
558 bool PanelManager::is_dragging_panel() const { | 600 bool PanelManager::is_dragging_panel() const { |
559 return dragging_panel_index_ != kInvalidPanelIndex; | 601 return dragging_panel_index_ != kInvalidPanelIndex; |
560 } | 602 } |
561 | 603 |
OLD | NEW |