OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/panels/panel_drag_controller.h" | |
16 #include "chrome/browser/ui/panels/panel_manager.h" | 15 #include "chrome/browser/ui/panels/panel_manager.h" |
17 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 16 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
18 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 // Width to height ratio is used to compute the default width or height | 22 // Width to height ratio is used to compute the default width or height |
24 // when only one value is provided. | 23 // when only one value is provided. |
25 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio | 24 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 NOTREACHED(); | 463 NOTREACHED(); |
465 break; | 464 break; |
466 } | 465 } |
467 | 466 |
468 int bottom = GetBottomPositionForExpansionState(expansion_state); | 467 int bottom = GetBottomPositionForExpansionState(expansion_state); |
469 bounds->set_y(bottom - bounds->height()); | 468 bounds->set_y(bottom - bounds->height()); |
470 } | 469 } |
471 | 470 |
472 void DockedPanelStrip::OnPanelAttentionStateChanged(Panel* panel) { | 471 void DockedPanelStrip::OnPanelAttentionStateChanged(Panel* panel) { |
473 DCHECK_EQ(this, panel->panel_strip()); | 472 DCHECK_EQ(this, panel->panel_strip()); |
473 Panel::ExpansionState state = panel->expansion_state(); | |
474 if (panel->IsDrawingAttention()) { | 474 if (panel->IsDrawingAttention()) { |
475 // Bring up the titlebar to get user's attention. | 475 // Bring up the titlebar to get user's attention. |
476 if (panel->expansion_state() == Panel::MINIMIZED) | 476 if (state == Panel::MINIMIZED) |
477 panel->SetExpansionState(Panel::TITLE_ONLY); | 477 panel->SetExpansionState(Panel::TITLE_ONLY); |
478 } else { | 478 return; |
479 // Maybe bring down the titlebar now that panel is not drawing attention. | |
480 if (panel->expansion_state() == Panel::TITLE_ONLY && !are_titlebars_up_) | |
481 panel->SetExpansionState(Panel::MINIMIZED); | |
482 } | 479 } |
480 | |
481 // Maybe bring down the titlebar now that panel is not drawing attention. | |
jianli
2012/05/16 18:37:41
nit: This comment does not apply to the check belo
| |
482 if (state != Panel::TITLE_ONLY || are_titlebars_up_) | |
483 return; | |
484 | |
485 // Leave titlebar up when dragging a panel. | |
jianli
2012/05/16 18:37:41
nit: Indeed we mean that this panel is being dragg
| |
486 if (dragging_panel_current_iterator_ != panels_.end() && | |
487 *dragging_panel_current_iterator_ == panel) | |
488 return; | |
489 | |
490 // Leave titlebar up if mouse is in/below the panel. | |
491 const gfx::Point mouse_position = | |
492 panel_manager_->mouse_watcher()->GetMousePosition(); | |
493 gfx::Rect bounds = panel->GetBounds(); | |
494 if (bounds.x() <= mouse_position.x() && | |
495 mouse_position.x() <= bounds.right() && | |
496 mouse_position.y() >= bounds.y()) | |
497 return; | |
498 | |
499 panel->SetExpansionState(Panel::MINIMIZED); | |
483 } | 500 } |
484 | 501 |
485 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, | 502 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, |
486 panel::ClickModifier modifier) { | 503 panel::ClickModifier modifier) { |
487 DCHECK_EQ(this, panel->panel_strip()); | 504 DCHECK_EQ(this, panel->panel_strip()); |
488 if (!IsPanelMinimized(panel)) | 505 if (!IsPanelMinimized(panel)) |
489 return; | 506 return; |
490 | 507 |
491 if (modifier == panel::APPLY_TO_ALL) | 508 if (modifier == panel::APPLY_TO_ALL) |
492 RestoreAll(); | 509 RestoreAll(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 | 647 |
631 gfx::Rect bounds = panel->GetBounds(); | 648 gfx::Rect bounds = panel->GetBounds(); |
632 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 649 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
633 mouse_y >= bounds.y()) | 650 mouse_y >= bounds.y()) |
634 return true; | 651 return true; |
635 } | 652 } |
636 return false; | 653 return false; |
637 } | 654 } |
638 | 655 |
639 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { | 656 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { |
640 if (are_titlebars_up_ == bring_up) | |
641 return; | |
642 are_titlebars_up_ = bring_up; | 657 are_titlebars_up_ = bring_up; |
643 | |
644 int task_delay_ms = 0; | 658 int task_delay_ms = 0; |
645 | 659 |
646 // If the auto-hiding bottom bar exists, delay the action until the bottom | 660 // If the auto-hiding bottom bar exists, delay the action until the bottom |
647 // bar is fully visible or hidden. We do not want both bottom bar and panel | 661 // bar is fully visible or hidden. We do not want both bottom bar and panel |
648 // titlebar to move at the same time but with different speeds. | 662 // titlebar to move at the same time but with different speeds. |
649 DisplaySettingsProvider* provider = | 663 DisplaySettingsProvider* provider = |
650 panel_manager_->display_settings_provider(); | 664 panel_manager_->display_settings_provider(); |
651 if (provider->IsAutoHidingDesktopBarEnabled( | 665 if (provider->IsAutoHidingDesktopBarEnabled( |
652 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { | 666 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { |
653 DisplaySettingsProvider::DesktopBarVisibility visibility = | 667 DisplaySettingsProvider::DesktopBarVisibility visibility = |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 921 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
908 // Refresh layout, but wait till active states settle. | 922 // Refresh layout, but wait till active states settle. |
909 // This lets us avoid refreshing too many times when one panel loses | 923 // This lets us avoid refreshing too many times when one panel loses |
910 // focus and another gains it. | 924 // focus and another gains it. |
911 ScheduleLayoutRefresh(); | 925 ScheduleLayoutRefresh(); |
912 } | 926 } |
913 | 927 |
914 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 928 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
915 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 929 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
916 } | 930 } |
OLD | NEW |