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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); |
474 if (panel->IsDrawingAttention()) { | 473 if (panel->IsDrawingAttention()) { |
475 // Bring up the titlebar to get user's attention. | 474 // Bring up the titlebar to get user's attention. |
476 if (panel->expansion_state() == Panel::MINIMIZED) | 475 if (panel->expansion_state() == Panel::MINIMIZED) |
477 panel->SetExpansionState(Panel::TITLE_ONLY); | 476 panel->SetExpansionState(Panel::TITLE_ONLY); |
478 } else { | 477 } else { |
479 // Maybe bring down the titlebar now that panel is not drawing attention. | 478 // Maybe bring down the titlebar now that panel is not drawing attention. |
480 if (panel->expansion_state() == Panel::TITLE_ONLY && !are_titlebars_up_) | 479 if (panel->expansion_state() == Panel::TITLE_ONLY && !are_titlebars_up_ |
480 && !IsMouseInPanel(panel)) | |
Andrei
2012/05/15 22:43:29
So now if one clicks on such panel and then moves
jennb
2012/05/15 22:53:54
If one clicks on a title-only panel and moves the
jianli
2012/05/15 22:59:47
nit: && should be placed at the end of last line.
jennb
2012/05/16 00:47:09
Done.
| |
481 panel->SetExpansionState(Panel::MINIMIZED); | 481 panel->SetExpansionState(Panel::MINIMIZED); |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 bool DockedPanelStrip::IsMouseInPanel(const Panel* panel) const { | |
486 if (dragging_panel_current_iterator_ != panels_.end() && | |
jianli
2012/05/15 22:59:47
Please comment this since it might be a bit confus
jennb
2012/05/16 00:47:09
Done.
| |
487 *dragging_panel_current_iterator_ == panel) | |
488 return true; | |
489 | |
490 const gfx::Point mouse_position = | |
491 panel_manager_->mouse_watcher()->GetMousePosition(); | |
492 gfx::Rect bounds = panel->GetBounds(); | |
493 return bounds.x() <= mouse_position.x() && | |
494 mouse_position.y() <= bounds.right() && | |
jianli
2012/05/15 22:59:47
y()?
Can we call gfx::Rect::Contains?
jennb
2012/05/16 00:47:09
Corrected.
| |
495 mouse_position.y() >= bounds.y(); | |
496 } | |
497 | |
485 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, | 498 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, |
486 panel::ClickModifier modifier) { | 499 panel::ClickModifier modifier) { |
487 DCHECK_EQ(this, panel->panel_strip()); | 500 DCHECK_EQ(this, panel->panel_strip()); |
488 if (!IsPanelMinimized(panel)) | 501 if (!IsPanelMinimized(panel)) |
489 return; | 502 return; |
490 | 503 |
491 if (modifier == panel::APPLY_TO_ALL) | 504 if (modifier == panel::APPLY_TO_ALL) |
492 RestoreAll(); | 505 RestoreAll(); |
493 else | 506 else |
494 RestorePanel(panel); | 507 RestorePanel(panel); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 | 643 |
631 gfx::Rect bounds = panel->GetBounds(); | 644 gfx::Rect bounds = panel->GetBounds(); |
632 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 645 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
633 mouse_y >= bounds.y()) | 646 mouse_y >= bounds.y()) |
634 return true; | 647 return true; |
635 } | 648 } |
636 return false; | 649 return false; |
637 } | 650 } |
638 | 651 |
639 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { | 652 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { |
640 if (are_titlebars_up_ == bring_up) | |
jianli
2012/05/15 22:59:47
Why do we need to remove this check?
jennb
2012/05/16 00:47:09
We may need to bring down panels that are in title
| |
641 return; | |
642 are_titlebars_up_ = bring_up; | 653 are_titlebars_up_ = bring_up; |
643 | |
644 int task_delay_ms = 0; | 654 int task_delay_ms = 0; |
645 | 655 |
646 // If the auto-hiding bottom bar exists, delay the action until the bottom | 656 // 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 | 657 // 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. | 658 // titlebar to move at the same time but with different speeds. |
649 DisplaySettingsProvider* provider = | 659 DisplaySettingsProvider* provider = |
650 panel_manager_->display_settings_provider(); | 660 panel_manager_->display_settings_provider(); |
651 if (provider->IsAutoHidingDesktopBarEnabled( | 661 if (provider->IsAutoHidingDesktopBarEnabled( |
652 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { | 662 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { |
653 DisplaySettingsProvider::DesktopBarVisibility visibility = | 663 DisplaySettingsProvider::DesktopBarVisibility visibility = |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 917 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
908 // Refresh layout, but wait till active states settle. | 918 // Refresh layout, but wait till active states settle. |
909 // This lets us avoid refreshing too many times when one panel loses | 919 // This lets us avoid refreshing too many times when one panel loses |
910 // focus and another gains it. | 920 // focus and another gains it. |
911 ScheduleLayoutRefresh(); | 921 ScheduleLayoutRefresh(); |
912 } | 922 } |
913 | 923 |
914 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 924 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
915 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 925 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
916 } | 926 } |
OLD | NEW |