| 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 // Panel is no longer drawing attention, but leave the panel in |
| 482 // title-only mode if all titlebars are currently up. |
| 483 if (state != Panel::TITLE_ONLY || are_titlebars_up_) |
| 484 return; |
| 485 |
| 486 // Leave titlebar up if panel is being dragged. |
| 487 if (dragging_panel_current_iterator_ != panels_.end() && |
| 488 *dragging_panel_current_iterator_ == panel) |
| 489 return; |
| 490 |
| 491 // Leave titlebar up if mouse is in/below the panel. |
| 492 const gfx::Point mouse_position = |
| 493 panel_manager_->mouse_watcher()->GetMousePosition(); |
| 494 gfx::Rect bounds = panel->GetBounds(); |
| 495 if (bounds.x() <= mouse_position.x() && |
| 496 mouse_position.x() <= bounds.right() && |
| 497 mouse_position.y() >= bounds.y()) |
| 498 return; |
| 499 |
| 500 // Bring down the titlebar now that panel is not drawing attention. |
| 501 panel->SetExpansionState(Panel::MINIMIZED); |
| 483 } | 502 } |
| 484 | 503 |
| 485 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, | 504 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, |
| 486 panel::ClickModifier modifier) { | 505 panel::ClickModifier modifier) { |
| 487 DCHECK_EQ(this, panel->panel_strip()); | 506 DCHECK_EQ(this, panel->panel_strip()); |
| 488 if (!IsPanelMinimized(panel)) | 507 if (!IsPanelMinimized(panel)) |
| 489 return; | 508 return; |
| 490 | 509 |
| 491 if (modifier == panel::APPLY_TO_ALL) | 510 if (modifier == panel::APPLY_TO_ALL) |
| 492 RestoreAll(); | 511 RestoreAll(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 649 |
| 631 gfx::Rect bounds = panel->GetBounds(); | 650 gfx::Rect bounds = panel->GetBounds(); |
| 632 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && | 651 if (bounds.x() <= mouse_x && mouse_x <= bounds.right() && |
| 633 mouse_y >= bounds.y()) | 652 mouse_y >= bounds.y()) |
| 634 return true; | 653 return true; |
| 635 } | 654 } |
| 636 return false; | 655 return false; |
| 637 } | 656 } |
| 638 | 657 |
| 639 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { | 658 void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { |
| 640 if (are_titlebars_up_ == bring_up) | |
| 641 return; | |
| 642 are_titlebars_up_ = bring_up; | 659 are_titlebars_up_ = bring_up; |
| 643 | |
| 644 int task_delay_ms = 0; | 660 int task_delay_ms = 0; |
| 645 | 661 |
| 646 // If the auto-hiding bottom bar exists, delay the action until the bottom | 662 // 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 | 663 // 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. | 664 // titlebar to move at the same time but with different speeds. |
| 649 DisplaySettingsProvider* provider = | 665 DisplaySettingsProvider* provider = |
| 650 panel_manager_->display_settings_provider(); | 666 panel_manager_->display_settings_provider(); |
| 651 if (provider->IsAutoHidingDesktopBarEnabled( | 667 if (provider->IsAutoHidingDesktopBarEnabled( |
| 652 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { | 668 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { |
| 653 DisplaySettingsProvider::DesktopBarVisibility visibility = | 669 DisplaySettingsProvider::DesktopBarVisibility visibility = |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 923 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
| 908 // Refresh layout, but wait till active states settle. | 924 // Refresh layout, but wait till active states settle. |
| 909 // This lets us avoid refreshing too many times when one panel loses | 925 // This lets us avoid refreshing too many times when one panel loses |
| 910 // focus and another gains it. | 926 // focus and another gains it. |
| 911 ScheduleLayoutRefresh(); | 927 ScheduleLayoutRefresh(); |
| 912 } | 928 } |
| 913 | 929 |
| 914 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 930 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
| 915 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 931 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
| 916 } | 932 } |
| OLD | NEW |