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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | |
13 #include "chrome/browser/ui/window_sizer.h" | 14 #include "chrome/browser/ui/window_sizer.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 // Invalid panel index. | 17 // Invalid panel index. |
17 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 18 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
18 | 19 |
19 // Default width and height of a panel. | 20 // Default width and height of a panel. |
20 const int kPanelDefaultWidth = 240; | 21 const int kPanelDefaultWidth = 240; |
21 const int kPanelDefaultHeight = 290; | 22 const int kPanelDefaultHeight = 290; |
22 | 23 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 int bottom = adjusted_work_area_.bottom(); | 517 int bottom = adjusted_work_area_.bottom(); |
517 if (expansion_state == Panel::MINIMIZED && | 518 if (expansion_state == Panel::MINIMIZED && |
518 auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { | 519 auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
519 bottom += auto_hiding_desktop_bar_->GetThickness( | 520 bottom += auto_hiding_desktop_bar_->GetThickness( |
520 AutoHidingDesktopBar::ALIGN_BOTTOM); | 521 AutoHidingDesktopBar::ALIGN_BOTTOM); |
521 } | 522 } |
522 | 523 |
523 return bottom; | 524 return bottom; |
524 } | 525 } |
525 | 526 |
527 BrowserWindow* PanelManager::GetNextPanelToActivate(Panel* panel) const { | |
jennb
2011/10/07 20:34:16
Why do we need to find the next panel within the s
jianli
2011/10/07 22:01:54
Per discussion, we changed to activate the last ac
| |
528 // First, find a panel that satisfies the following criteria: | |
529 // 1) expanded | |
530 // 2) from the same extension | |
531 // 3) closer to the panel to be deactivated, if there're more than one panels | |
532 // that meet 1 and 2 | |
533 const Extension* extension = panel->GetExtension(); | |
534 size_t panel_index; | |
535 for (panel_index = 0; panel_index < panels_.size(); ++panel_index) { | |
536 if (panels_[panel_index] == panel) | |
537 break; | |
538 } | |
539 DCHECK(panel_index < panels_.size()); | |
540 | |
541 size_t max_index_delta = std::max(panel_index, panels_.size() - panel_index); | |
Dmitry Titov
2011/10/07 20:29:15
This needs a comment. Why this specific math?
jianli
2011/10/07 22:01:54
Not needed due to deactivation algorithm change.
| |
542 for (size_t delta = 1; delta <= max_index_delta; ++delta) { | |
543 if (panel_index + delta < panels_.size()) { | |
544 Panel* next_panel = panels_[panel_index + delta]; | |
545 if (next_panel->expansion_state() == Panel::EXPANDED && | |
546 next_panel->GetExtension() == extension) { | |
547 return next_panel->browser()->window(); | |
548 } | |
549 } | |
550 | |
551 if (panel_index >= delta) { | |
Dmitry Titov
2011/10/07 20:29:15
would be more readable as 'panel_index - delta >=
jianli
2011/10/07 22:01:54
Not needed due to deactivation algorithm change.
| |
552 Panel* next_panel = panels_[panel_index - delta]; | |
553 if (next_panel->expansion_state() == Panel::EXPANDED && | |
554 next_panel->GetExtension() == extension) { | |
555 return next_panel->browser()->window(); | |
556 } | |
557 } | |
558 } | |
559 | |
560 // Then, find the last active tabbed window. | |
561 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); | |
562 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); | |
563 for (; (iter != end); ++iter) { | |
564 Browser* browser = *iter; | |
565 if (browser->is_type_tabbed()) | |
566 return browser->window(); | |
567 } | |
568 | |
569 return NULL; | |
570 } | |
571 | |
526 void PanelManager::OnMouseMove(const gfx::Point& mouse_position) { | 572 void PanelManager::OnMouseMove(const gfx::Point& mouse_position) { |
527 bool bring_up_titlebars = ShouldBringUpTitlebars(mouse_position.x(), | 573 bool bring_up_titlebars = ShouldBringUpTitlebars(mouse_position.x(), |
528 mouse_position.y()); | 574 mouse_position.y()); |
529 if (are_titlebars_up_ == bring_up_titlebars) | 575 if (are_titlebars_up_ == bring_up_titlebars) |
530 return; | 576 return; |
531 are_titlebars_up_ = bring_up_titlebars; | 577 are_titlebars_up_ = bring_up_titlebars; |
532 BringUpOrDownTitlebars(bring_up_titlebars); | 578 BringUpOrDownTitlebars(bring_up_titlebars); |
533 } | 579 } |
534 | 580 |
535 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { | 581 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 Panel* panel = *iter; | 643 Panel* panel = *iter; |
598 // A panel can at most grow to take over all the available space that is | 644 // A panel can at most grow to take over all the available space that is |
599 // returned by GetRightMostAvailablePosition. | 645 // returned by GetRightMostAvailablePosition. |
600 int width_can_grow_to = | 646 int width_can_grow_to = |
601 panel->GetBounds().width() + GetRightMostAvailablePosition(); | 647 panel->GetBounds().width() + GetRightMostAvailablePosition(); |
602 panel->SetMaxSize(gfx::Size( | 648 panel->SetMaxSize(gfx::Size( |
603 std::min(width_can_grow_to, GetMaxPanelWidth()), | 649 std::min(width_can_grow_to, GetMaxPanelWidth()), |
604 GetMaxPanelHeight())); | 650 GetMaxPanelHeight())); |
605 } | 651 } |
606 } | 652 } |
OLD | NEW |