OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/browser/browser.h" | 5 #include "mash/browser/browser.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 86 |
87 Tab* tab_; | 87 Tab* tab_; |
88 | 88 |
89 DISALLOW_COPY_AND_ASSIGN(Background); | 89 DISALLOW_COPY_AND_ASSIGN(Background); |
90 }; | 90 }; |
91 | 91 |
92 Tab(std::unique_ptr<navigation::View> view, | 92 Tab(std::unique_ptr<navigation::View> view, |
93 views::ButtonListener* listener) | 93 views::ButtonListener* listener) |
94 : views::LabelButton(listener, base::ASCIIToUTF16("Blank")), | 94 : views::LabelButton(listener, base::ASCIIToUTF16("Blank")), |
95 view_(std::move(view)) { | 95 view_(std::move(view)) { |
96 view_->SetResizerSize(gfx::Size(16, 16)); | |
97 view_->AddObserver(this); | 96 view_->AddObserver(this); |
98 set_background(new Background(this)); | 97 set_background(new Background(this)); |
99 } | 98 } |
100 ~Tab() override { | 99 ~Tab() override { |
101 view_->RemoveObserver(this); | 100 view_->RemoveObserver(this); |
102 } | 101 } |
103 | 102 |
104 bool selected() const { return selected_; } | 103 bool selected() const { return selected_; } |
105 | 104 |
106 mus::Window* window() { return window_; } | 105 mus::Window* window() { return window_; } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 if (tab_index < selected_index_) | 225 if (tab_index < selected_index_) |
227 --selected_index_; | 226 --selected_index_; |
228 DCHECK(it != tabs_.end()); | 227 DCHECK(it != tabs_.end()); |
229 tabs_.erase(it); | 228 tabs_.erase(it); |
230 RemoveObserver(tab); | 229 RemoveObserver(tab); |
231 tab_container_->RemoveChildView(tab); | 230 tab_container_->RemoveChildView(tab); |
232 if (tab->selected()) { | 231 if (tab->selected()) { |
233 int next_selected_index = selected_index_; | 232 int next_selected_index = selected_index_; |
234 if (selected_index_ == static_cast<int>(tabs_.size())) | 233 if (selected_index_ == static_cast<int>(tabs_.size())) |
235 --next_selected_index; | 234 --next_selected_index; |
236 SelectTab(tabs_[next_selected_index]); | 235 if (next_selected_index >= 0) |
236 SelectTab(tabs_[next_selected_index]); | |
237 } | 237 } |
238 Layout(); | 238 Layout(); |
239 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabRemoved(tab)); | 239 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabRemoved(tab)); |
240 delete tab; | 240 delete tab; |
241 } | 241 } |
242 | 242 |
243 bool empty() const { return tabs_.empty(); } | 243 bool empty() const { return tabs_.empty(); } |
244 | 244 |
245 void SelectTab(Tab* tab) { | 245 void SelectTab(Tab* tab) { |
246 auto it = std::find(tabs_.begin(), tabs_.end(), tab); | 246 auto it = std::find(tabs_.begin(), tabs_.end(), tab); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 if (GetWidget()) | 714 if (GetWidget()) |
715 GetWidget()->UpdateWindowTitle(); | 715 GetWidget()->UpdateWindowTitle(); |
716 } | 716 } |
717 | 717 |
718 // navigation::ViewDelegate: | 718 // navigation::ViewDelegate: |
719 void ViewCreated(navigation::View* source, | 719 void ViewCreated(navigation::View* source, |
720 std::unique_ptr<navigation::View> view, | 720 std::unique_ptr<navigation::View> view, |
721 bool is_popup, | 721 bool is_popup, |
722 const gfx::Rect& initial_rect, | 722 const gfx::Rect& initial_rect, |
723 bool user_gesture) override { | 723 bool user_gesture) override { |
724 if (is_popup) { | 724 if (is_popup) |
725 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 725 CreateNewWindow(std::move(view), initial_rect, is_popup); |
726 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, | 726 else |
727 std::move(view)), | |
728 nullptr, initial_rect); | |
729 window->Show(); | |
730 browser_->AddWindow(window); | |
731 } else { | |
732 tab_strip_->AddTab(std::move(view)); | 727 tab_strip_->AddTab(std::move(view)); |
733 } | |
734 } | 728 } |
735 void Close(navigation::View* source) override { | 729 void Close(navigation::View* source) override { |
736 tab_strip_->CloseTabForView(source); | 730 tab_strip_->CloseTabForView(source); |
737 if (tab_strip_->empty()) | 731 if (tab_strip_->empty()) |
738 GetWidget()->Close(); | 732 GetWidget()->Close(); |
739 } | 733 } |
734 void OpenURL(navigation::View* source, | |
735 navigation::mojom::OpenURLParamsPtr params) override { | |
736 switch (params->disposition) { | |
737 case navigation::mojom::WindowOpenDisposition::CURRENT_TAB: | |
jam
2016/06/10 23:19:10
nit:indentation is off
| |
738 selected_view()->NavigateToURL(params->url); | |
739 break; | |
740 case navigation::mojom::WindowOpenDisposition::NEW_FOREGROUND_TAB: | |
741 tab_strip_->AddTab(browser_->CreateView()); | |
742 tab_strip_->selected_tab()->view()->NavigateToURL(params->url); | |
743 break; | |
744 case navigation::mojom::WindowOpenDisposition::NEW_POPUP: | |
745 case navigation::mojom::WindowOpenDisposition::NEW_WINDOW: { | |
746 std::unique_ptr<navigation::View> view = browser_->CreateView(); | |
747 view->NavigateToURL(params->url); | |
748 CreateNewWindow(std::move(view), gfx::Rect(), | |
749 params->disposition == | |
750 navigation::mojom::WindowOpenDisposition::NEW_POPUP); | |
751 break; | |
752 } | |
753 default: | |
754 break; | |
755 } | |
756 } | |
740 | 757 |
741 // navigation::ViewObserver: | 758 // navigation::ViewObserver: |
742 void LoadingStateChanged(navigation::View* view) override { | 759 void LoadingStateChanged(navigation::View* view) override { |
743 if (view->is_loading()) { | 760 if (view->is_loading()) { |
744 reload_button_->SetText(base::ASCIIToUTF16("Stop")); | 761 reload_button_->SetText(base::ASCIIToUTF16("Stop")); |
745 throbber_->Start(); | 762 throbber_->Start(); |
746 } else { | 763 } else { |
747 reload_button_->SetText(base::ASCIIToUTF16("Reload")); | 764 reload_button_->SetText(base::ASCIIToUTF16("Reload")); |
748 throbber_->Stop(); | 765 throbber_->Stop(); |
749 progress_bar_->SetProgress(0.f); | 766 progress_bar_->SetProgress(0.f); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 } | 800 } |
784 | 801 |
785 navigation::View* selected_view() { | 802 navigation::View* selected_view() { |
786 return const_cast<navigation::View*>( | 803 return const_cast<navigation::View*>( |
787 static_cast<const UI*>(this)->selected_view()); | 804 static_cast<const UI*>(this)->selected_view()); |
788 } | 805 } |
789 const navigation::View* selected_view() const { | 806 const navigation::View* selected_view() const { |
790 return tab_strip_->selected_tab()->view(); | 807 return tab_strip_->selected_tab()->view(); |
791 } | 808 } |
792 | 809 |
810 void CreateNewWindow(std::unique_ptr<navigation::View> view, | |
811 const gfx::Rect& initial_bounds, | |
812 bool is_popup) { | |
813 gfx::Rect bounds = initial_bounds; | |
814 if (bounds.IsEmpty()) | |
815 bounds = gfx::Rect(10, 10, 400, 300); | |
816 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | |
817 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, | |
818 std::move(view)), | |
819 nullptr, bounds); | |
820 window->Show(); | |
821 browser_->AddWindow(window); | |
822 } | |
823 | |
793 void ToggleDebugView() { | 824 void ToggleDebugView() { |
794 showing_debug_view_ = !showing_debug_view_; | 825 showing_debug_view_ = !showing_debug_view_; |
795 Layout(); | 826 Layout(); |
796 } | 827 } |
797 | 828 |
798 Browser* browser_; | 829 Browser* browser_; |
799 | 830 |
800 Type type_; | 831 Type type_; |
801 | 832 |
802 TabStrip* tab_strip_; | 833 TabStrip* tab_strip_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 AddWindow(window); | 900 AddWindow(window); |
870 } | 901 } |
871 | 902 |
872 void Browser::Create(shell::Connection* connection, | 903 void Browser::Create(shell::Connection* connection, |
873 mojom::LaunchableRequest request) { | 904 mojom::LaunchableRequest request) { |
874 bindings_.AddBinding(this, std::move(request)); | 905 bindings_.AddBinding(this, std::move(request)); |
875 } | 906 } |
876 | 907 |
877 } // namespace browser | 908 } // namespace browser |
878 } // namespace mash | 909 } // namespace mash |
OLD | NEW |