| 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" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "content/public/common/service_names.mojom.h" | 16 #include "content/public/common/service_names.mojom.h" |
| 17 #include "mash/browser/debug_view.h" | 17 #include "mash/browser/debug_view.h" |
| 18 #include "mash/public/interfaces/launchable.mojom.h" | 18 #include "mash/public/interfaces/launchable.mojom.h" |
| 19 #include "services/navigation/public/cpp/view.h" | 19 #include "services/navigation/public/cpp/view.h" |
| 20 #include "services/navigation/public/cpp/view_delegate.h" | 20 #include "services/navigation/public/cpp/view_delegate.h" |
| 21 #include "services/navigation/public/cpp/view_observer.h" | 21 #include "services/navigation/public/cpp/view_observer.h" |
| 22 #include "services/navigation/public/interfaces/view.mojom.h" | 22 #include "services/navigation/public/interfaces/view.mojom.h" |
| 23 #include "services/service_manager/public/c/main.h" | 23 #include "services/service_manager/public/c/main.h" |
| 24 #include "services/service_manager/public/cpp/connector.h" | 24 #include "services/service_manager/public/cpp/connector.h" |
| 25 #include "services/service_manager/public/cpp/interface_registry.h" | 25 #include "services/service_manager/public/cpp/interface_registry.h" |
| 26 #include "services/service_manager/public/cpp/service.h" | 26 #include "services/service_manager/public/cpp/service.h" |
| 27 #include "services/service_manager/public/cpp/service_context.h" | 27 #include "services/service_manager/public/cpp/service_context.h" |
| 28 #include "services/service_manager/public/cpp/service_runner.h" | 28 #include "services/service_manager/public/cpp/service_runner.h" |
| 29 #include "services/tracing/public/cpp/provider.h" | 29 #include "services/tracing/public/cpp/provider.h" |
| 30 #include "services/ui/public/cpp/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "services/ui/public/cpp/window_tree_client.h" | |
| 32 #include "ui/aura/mus/mus_util.h" | |
| 33 #include "ui/base/models/menu_model.h" | 31 #include "ui/base/models/menu_model.h" |
| 34 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 35 #include "ui/gfx/paint_throbber.h" | 33 #include "ui/gfx/paint_throbber.h" |
| 36 #include "ui/gfx/text_constants.h" | 34 #include "ui/gfx/text_constants.h" |
| 37 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
| 38 #include "ui/views/background.h" | 36 #include "ui/views/background.h" |
| 39 #include "ui/views/controls/button/label_button.h" | 37 #include "ui/views/controls/button/label_button.h" |
| 40 #include "ui/views/controls/menu/menu_model_adapter.h" | 38 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 41 #include "ui/views/controls/menu/menu_runner.h" | 39 #include "ui/views/controls/menu/menu_runner.h" |
| 42 #include "ui/views/controls/textfield/textfield.h" | 40 #include "ui/views/controls/textfield/textfield.h" |
| 43 #include "ui/views/controls/textfield/textfield_controller.h" | 41 #include "ui/views/controls/textfield/textfield_controller.h" |
| 44 #include "ui/views/layout/box_layout.h" | 42 #include "ui/views/layout/box_layout.h" |
| 45 #include "ui/views/mus/aura_init.h" | 43 #include "ui/views/mus/aura_init.h" |
| 46 #include "ui/views/mus/window_manager_connection.h" | 44 #include "ui/views/widget/widget.h" |
| 47 #include "ui/views/widget/widget_delegate.h" | 45 #include "ui/views/widget/widget_delegate.h" |
| 48 #include "url/gurl.h" | 46 #include "url/gurl.h" |
| 49 | 47 |
| 50 namespace mash { | 48 namespace mash { |
| 51 namespace browser { | 49 namespace browser { |
| 52 | 50 |
| 53 void EnableButton(views::CustomButton* button, bool enabled) { | 51 void EnableButton(views::CustomButton* button, bool enabled) { |
| 54 button->SetState(enabled ? views::Button::STATE_NORMAL | 52 button->SetState(enabled ? views::Button::STATE_NORMAL |
| 55 : views::Button::STATE_DISABLED); | 53 : views::Button::STATE_DISABLED); |
| 56 } | 54 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 view_(std::move(view)) { | 96 view_(std::move(view)) { |
| 99 view_->AddObserver(this); | 97 view_->AddObserver(this); |
| 100 set_background(new Background(this)); | 98 set_background(new Background(this)); |
| 101 } | 99 } |
| 102 ~Tab() override { | 100 ~Tab() override { |
| 103 view_->RemoveObserver(this); | 101 view_->RemoveObserver(this); |
| 104 } | 102 } |
| 105 | 103 |
| 106 bool selected() const { return selected_; } | 104 bool selected() const { return selected_; } |
| 107 | 105 |
| 108 ui::Window* window() { return window_; } | 106 aura::Window* window() { return window_; } |
| 109 void SetWindow(ui::Window* window) { | 107 void SetWindow(aura::Window* window) { |
| 110 window_ = window; | 108 window_ = window; |
| 111 window_->SetVisible(selected_); | 109 if (selected_) |
| 110 window_->Show(); |
| 111 else |
| 112 window_->Hide(); |
| 112 view_->EmbedInWindow(window_); | 113 view_->EmbedInWindow(window_); |
| 113 } | 114 } |
| 114 navigation::View* view() { return view_.get(); } | 115 navigation::View* view() { return view_.get(); } |
| 115 | 116 |
| 116 private: | 117 private: |
| 117 // views::View: | 118 // views::View: |
| 118 gfx::Size GetPreferredSize() const override { | 119 gfx::Size GetPreferredSize() const override { |
| 119 gfx::Size ps = views::LabelButton::GetPreferredSize(); | 120 gfx::Size ps = views::LabelButton::GetPreferredSize(); |
| 120 ps.set_width(180); | 121 ps.set_width(180); |
| 121 return ps; | 122 return ps; |
| 122 } | 123 } |
| 123 | 124 |
| 124 // navigation::ViewObserver: | 125 // navigation::ViewObserver: |
| 125 void NavigationStateChanged(navigation::View* view) override { | 126 void NavigationStateChanged(navigation::View* view) override { |
| 126 if (!view->title().empty()) | 127 if (!view->title().empty()) |
| 127 SetText(view->title()); | 128 SetText(view->title()); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // TabStripObserver: | 131 // TabStripObserver: |
| 131 void OnTabSelected(Tab* selected) override { | 132 void OnTabSelected(Tab* selected) override { |
| 132 selected_ = selected == this; | 133 selected_ = selected == this; |
| 133 SetTextColor(views::Button::STATE_NORMAL, | 134 SetTextColor(views::Button::STATE_NORMAL, |
| 134 selected_ ? SK_ColorWHITE : SK_ColorBLACK); | 135 selected_ ? SK_ColorWHITE : SK_ColorBLACK); |
| 135 SetTextColor(views::Button::STATE_HOVERED, | 136 SetTextColor(views::Button::STATE_HOVERED, |
| 136 selected_ ? SK_ColorWHITE : SK_ColorBLACK); | 137 selected_ ? SK_ColorWHITE : SK_ColorBLACK); |
| 137 SetTextColor(views::Button::STATE_PRESSED, | 138 SetTextColor(views::Button::STATE_PRESSED, |
| 138 selected_ ? SK_ColorWHITE : SK_ColorBLACK); | 139 selected_ ? SK_ColorWHITE : SK_ColorBLACK); |
| 139 if (window_) | 140 if (window_) { |
| 140 window_->SetVisible(selected_); | 141 if (selected_) |
| 142 window_->Show(); |
| 143 else |
| 144 window_->Hide(); |
| 145 } |
| 141 } | 146 } |
| 142 | 147 |
| 143 ui::Window* window_ = nullptr; | 148 aura::Window* window_ = nullptr; |
| 144 std::unique_ptr<navigation::View> view_; | 149 std::unique_ptr<navigation::View> view_; |
| 145 bool selected_ = false; | 150 bool selected_ = false; |
| 146 | 151 |
| 147 DISALLOW_COPY_AND_ASSIGN(Tab); | 152 DISALLOW_COPY_AND_ASSIGN(Tab); |
| 148 }; | 153 }; |
| 149 | 154 |
| 150 class TabStrip : public views::View, | 155 class TabStrip : public views::View, |
| 151 public views::ButtonListener { | 156 public views::ButtonListener { |
| 152 public: | 157 public: |
| 153 class Delegate { | 158 class Delegate { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 179 tab_container_->SetLayoutManager(tab_container_layout); | 184 tab_container_->SetLayoutManager(tab_container_layout); |
| 180 AddChildView(tab_container_); | 185 AddChildView(tab_container_); |
| 181 layout->SetFlexForView(tab_container_, 1); | 186 layout->SetFlexForView(tab_container_, 1); |
| 182 AddChildView(new_tab_button_); | 187 AddChildView(new_tab_button_); |
| 183 } | 188 } |
| 184 ~TabStrip() override { | 189 ~TabStrip() override { |
| 185 for (auto* tab : tabs_) | 190 for (auto* tab : tabs_) |
| 186 RemoveObserver(tab); | 191 RemoveObserver(tab); |
| 187 } | 192 } |
| 188 | 193 |
| 189 void SetContainerWindow(ui::Window* container) { | 194 void SetContainerWindow(aura::Window* container) { |
| 190 DCHECK(!container_); | 195 DCHECK(!container_); |
| 191 container_ = container; | 196 container_ = container; |
| 192 for (auto* tab : tabs_) { | 197 for (auto* tab : tabs_) { |
| 193 ui::Window* window = container_->window_tree()->NewWindow(); | 198 aura::Window* window = new aura::Window(nullptr); |
| 199 window->Init(ui::LAYER_NOT_DRAWN); |
| 194 container_->AddChild(window); | 200 container_->AddChild(window); |
| 195 tab->SetWindow(window); | 201 tab->SetWindow(window); |
| 196 } | 202 } |
| 197 } | 203 } |
| 198 | 204 |
| 199 void AddTab(std::unique_ptr<navigation::View> view) { | 205 void AddTab(std::unique_ptr<navigation::View> view) { |
| 200 selected_index_ = static_cast<int>(tabs_.size()); | 206 selected_index_ = static_cast<int>(tabs_.size()); |
| 201 Tab* tab = new Tab(std::move(view), this); | 207 Tab* tab = new Tab(std::move(view), this); |
| 202 // We won't have a WindowTree until we're added to a view hierarchy. | 208 // We won't have a WindowTree until we're added to a view hierarchy. |
| 203 if (container_) { | 209 if (container_) { |
| 204 ui::Window* window = container_->window_tree()->NewWindow(); | 210 aura::Window* window = new aura::Window(nullptr); |
| 211 window->Init(ui::LAYER_NOT_DRAWN); |
| 205 container_->AddChild(window); | 212 container_->AddChild(window); |
| 206 tab->SetWindow(window); | 213 tab->SetWindow(window); |
| 207 } | 214 } |
| 208 AddObserver(tab); | 215 AddObserver(tab); |
| 209 tabs_.push_back(tab); | 216 tabs_.push_back(tab); |
| 210 tab_container_->AddChildView(tab); | 217 tab_container_->AddChildView(tab); |
| 211 for (auto& observer : observers_) | 218 for (auto& observer : observers_) |
| 212 observer.OnTabAdded(tab); | 219 observer.OnTabAdded(tab); |
| 213 SelectTab(tab); | 220 SelectTab(tab); |
| 214 } | 221 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 else if (sender == new_tab_button_ && delegate_) | 293 else if (sender == new_tab_button_ && delegate_) |
| 287 delegate_->NewTab(); | 294 delegate_->NewTab(); |
| 288 } | 295 } |
| 289 | 296 |
| 290 Delegate* delegate_; | 297 Delegate* delegate_; |
| 291 views::View* tab_container_; | 298 views::View* tab_container_; |
| 292 views::LabelButton* new_tab_button_; | 299 views::LabelButton* new_tab_button_; |
| 293 std::vector<Tab*> tabs_; | 300 std::vector<Tab*> tabs_; |
| 294 int selected_index_ = -1; | 301 int selected_index_ = -1; |
| 295 base::ObserverList<TabStripObserver> observers_; | 302 base::ObserverList<TabStripObserver> observers_; |
| 296 ui::Window* container_ = nullptr; | 303 aura::Window* container_ = nullptr; |
| 297 | 304 |
| 298 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 305 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
| 299 }; | 306 }; |
| 300 | 307 |
| 301 class NavMenuModel : public ui::MenuModel { | 308 class NavMenuModel : public ui::MenuModel { |
| 302 public: | 309 public: |
| 303 class Delegate { | 310 class Delegate { |
| 304 public: | 311 public: |
| 305 virtual void NavigateToOffset(int offset) = 0; | 312 virtual void NavigateToOffset(int offset) = 0; |
| 306 }; | 313 }; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 int height = local_bounds.height() - y - debug_view_height; | 681 int height = local_bounds.height() - y - debug_view_height; |
| 675 content_area_->SetBounds( | 682 content_area_->SetBounds( |
| 676 gfx::Rect(offset.x(), offset.y(), width, height)); | 683 gfx::Rect(offset.x(), offset.y(), width, height)); |
| 677 for (auto* child : content_area_->children()) | 684 for (auto* child : content_area_->children()) |
| 678 child->SetBounds(gfx::Rect(0, 0, width, height)); | 685 child->SetBounds(gfx::Rect(0, 0, width, height)); |
| 679 } | 686 } |
| 680 } | 687 } |
| 681 void ViewHierarchyChanged( | 688 void ViewHierarchyChanged( |
| 682 const views::View::ViewHierarchyChangedDetails& details) override { | 689 const views::View::ViewHierarchyChangedDetails& details) override { |
| 683 if (details.is_add && GetWidget() && !content_area_) { | 690 if (details.is_add && GetWidget() && !content_area_) { |
| 684 ui::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); | 691 aura::Window* window = GetWidget()->GetNativeWindow(); |
| 685 content_area_ = window->window_tree()->NewWindow(nullptr); | 692 content_area_ = new aura::Window(nullptr); |
| 686 content_area_->SetVisible(true); | 693 content_area_->Init(ui::LAYER_NOT_DRAWN); |
| 694 content_area_->Show(); |
| 687 window->AddChild(content_area_); | 695 window->AddChild(content_area_); |
| 688 tab_strip_->SetContainerWindow(content_area_); | 696 tab_strip_->SetContainerWindow(content_area_); |
| 689 } | 697 } |
| 690 } | 698 } |
| 691 | 699 |
| 692 // Overridden from views::TextFieldController: | 700 // Overridden from views::TextFieldController: |
| 693 bool HandleKeyEvent(views::Textfield* sender, | 701 bool HandleKeyEvent(views::Textfield* sender, |
| 694 const ui::KeyEvent& key_event) override { | 702 const ui::KeyEvent& key_event) override { |
| 695 if (key_event.type() == ui::ET_KEY_PRESSED && | 703 if (key_event.type() == ui::ET_KEY_PRESSED && |
| 696 key_event.key_code() == ui::VKEY_RETURN) | 704 key_event.key_code() == ui::VKEY_RETURN) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 | 842 |
| 835 TabStrip* tab_strip_; | 843 TabStrip* tab_strip_; |
| 836 views::LabelButton* back_button_; | 844 views::LabelButton* back_button_; |
| 837 views::LabelButton* forward_button_; | 845 views::LabelButton* forward_button_; |
| 838 views::LabelButton* reload_button_; | 846 views::LabelButton* reload_button_; |
| 839 views::Textfield* prompt_; | 847 views::Textfield* prompt_; |
| 840 views::LabelButton* debug_button_; | 848 views::LabelButton* debug_button_; |
| 841 Throbber* throbber_; | 849 Throbber* throbber_; |
| 842 ProgressBar* progress_bar_; | 850 ProgressBar* progress_bar_; |
| 843 | 851 |
| 844 ui::Window* content_area_ = nullptr; | 852 aura::Window* content_area_ = nullptr; |
| 845 | 853 |
| 846 DebugView* debug_view_; | 854 DebugView* debug_view_; |
| 847 bool showing_debug_view_ = false; | 855 bool showing_debug_view_ = false; |
| 848 | 856 |
| 849 DISALLOW_COPY_AND_ASSIGN(UI); | 857 DISALLOW_COPY_AND_ASSIGN(UI); |
| 850 }; | 858 }; |
| 851 | 859 |
| 852 Browser::Browser() {} | 860 Browser::Browser() {} |
| 853 Browser::~Browser() {} | 861 Browser::~Browser() {} |
| 854 | 862 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 868 navigation::mojom::ViewFactoryPtr factory; | 876 navigation::mojom::ViewFactoryPtr factory; |
| 869 context()->connector()->ConnectToInterface( | 877 context()->connector()->ConnectToInterface( |
| 870 content::mojom::kBrowserServiceName, &factory); | 878 content::mojom::kBrowserServiceName, &factory); |
| 871 return base::MakeUnique<navigation::View>(std::move(factory)); | 879 return base::MakeUnique<navigation::View>(std::move(factory)); |
| 872 } | 880 } |
| 873 | 881 |
| 874 void Browser::OnStart() { | 882 void Browser::OnStart() { |
| 875 tracing_.Initialize(context()->connector(), context()->identity().name()); | 883 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 876 | 884 |
| 877 aura_init_ = base::MakeUnique<views::AuraInit>( | 885 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 878 context()->connector(), context()->identity(), "views_mus_resources.pak"); | 886 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 879 window_manager_connection_ = views::WindowManagerConnection::Create( | 887 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); |
| 880 context()->connector(), context()->identity()); | |
| 881 } | 888 } |
| 882 | 889 |
| 883 bool Browser::OnConnect(const service_manager::ServiceInfo& remote_info, | 890 bool Browser::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 884 service_manager::InterfaceRegistry* registry) { | 891 service_manager::InterfaceRegistry* registry) { |
| 885 registry->AddInterface<mojom::Launchable>(this); | 892 registry->AddInterface<mojom::Launchable>(this); |
| 886 return true; | 893 return true; |
| 887 } | 894 } |
| 888 | 895 |
| 889 void Browser::Launch(uint32_t what, mojom::LaunchMode how) { | 896 void Browser::Launch(uint32_t what, mojom::LaunchMode how) { |
| 890 bool reuse = | 897 bool reuse = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 902 AddWindow(window); | 909 AddWindow(window); |
| 903 } | 910 } |
| 904 | 911 |
| 905 void Browser::Create(const service_manager::Identity& remote_identity, | 912 void Browser::Create(const service_manager::Identity& remote_identity, |
| 906 mojom::LaunchableRequest request) { | 913 mojom::LaunchableRequest request) { |
| 907 bindings_.AddBinding(this, std::move(request)); | 914 bindings_.AddBinding(this, std::move(request)); |
| 908 } | 915 } |
| 909 | 916 |
| 910 } // namespace browser | 917 } // namespace browser |
| 911 } // namespace mash | 918 } // namespace mash |
| OLD | NEW |