Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: mandoline/ui/desktop_ui/browser_window.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mandoline/ui/desktop_ui/browser_window.h ('k') | mandoline/ui/omnibox/omnibox_application.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mandoline/ui/desktop_ui/browser_window.h" 5 #include "mandoline/ui/desktop_ui/browser_window.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "components/mus/public/cpp/event_matcher.h" 17 #include "components/mus/public/cpp/event_matcher.h"
18 #include "components/mus/public/cpp/scoped_window_ptr.h" 18 #include "components/mus/public/cpp/scoped_window_ptr.h"
19 #include "components/mus/public/cpp/window_tree_host_factory.h" 19 #include "components/mus/public/cpp/window_tree_host_factory.h"
20 #include "mandoline/ui/desktop_ui/browser_commands.h" 20 #include "mandoline/ui/desktop_ui/browser_commands.h"
21 #include "mandoline/ui/desktop_ui/browser_manager.h" 21 #include "mandoline/ui/desktop_ui/browser_manager.h"
22 #include "mandoline/ui/desktop_ui/find_bar_view.h" 22 #include "mandoline/ui/desktop_ui/find_bar_view.h"
23 #include "mandoline/ui/desktop_ui/public/interfaces/omnibox.mojom.h" 23 #include "mandoline/ui/desktop_ui/public/interfaces/omnibox.mojom.h"
24 #include "mandoline/ui/desktop_ui/toolbar_view.h" 24 #include "mandoline/ui/desktop_ui/toolbar_view.h"
25 #include "mojo/common/common_type_converters.h" 25 #include "mojo/common/common_type_converters.h"
26 #include "mojo/converters/geometry/geometry_type_converters.h" 26 #include "mojo/converters/geometry/geometry_type_converters.h"
27 #include "mojo/services/tracing/public/cpp/switches.h" 27 #include "mojo/services/tracing/public/cpp/switches.h"
28 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" 28 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h"
29 #include "mojo/shell/public/cpp/shell.h"
29 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
30 #include "ui/mojo/init/ui_init.h" 31 #include "ui/mojo/init/ui_init.h"
31 #include "ui/views/background.h" 32 #include "ui/views/background.h"
32 #include "ui/views/controls/button/label_button.h" 33 #include "ui/views/controls/button/label_button.h"
33 #include "ui/views/layout/layout_manager.h" 34 #include "ui/views/layout/layout_manager.h"
34 #include "ui/views/mus/aura_init.h" 35 #include "ui/views/mus/aura_init.h"
35 #include "ui/views/mus/display_converter.h" 36 #include "ui/views/mus/display_converter.h"
36 #include "ui/views/mus/native_widget_mus.h" 37 #include "ui/views/mus/native_widget_mus.h"
37 #include "ui/views/widget/widget_delegate.h" 38 #include "ui/views/widget/widget_delegate.h"
38 39
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 98 }
98 99
99 BrowserWindow* window_; 100 BrowserWindow* window_;
100 101
101 DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl); 102 DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl);
102 }; 103 };
103 104
104 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
105 // BrowserWindow, public: 106 // BrowserWindow, public:
106 107
107 BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app, 108 BrowserWindow::BrowserWindow(mojo::Shell* shell,
108 mus::mojom::WindowTreeHostFactory* host_factory, 109 mus::mojom::WindowTreeHostFactory* host_factory,
109 BrowserManager* manager) 110 BrowserManager* manager)
110 : app_(app), 111 : shell_(shell),
111 window_manager_client_(nullptr), 112 window_manager_client_(nullptr),
112 manager_(manager), 113 manager_(manager),
113 toolbar_view_(nullptr), 114 toolbar_view_(nullptr),
114 progress_bar_(nullptr), 115 progress_bar_(nullptr),
115 find_bar_view_(nullptr), 116 find_bar_view_(nullptr),
116 root_(nullptr), 117 root_(nullptr),
117 content_(nullptr), 118 content_(nullptr),
118 omnibox_view_(nullptr), 119 omnibox_view_(nullptr),
119 find_active_(0), 120 find_active_(0),
120 find_count_(0), 121 find_count_(0),
(...skipping 22 matching lines...) Expand all
143 void BrowserWindow::Close() { 144 void BrowserWindow::Close() {
144 if (root_) 145 if (root_)
145 mus::ScopedWindowPtr::DeleteWindowOrWindowManager(root_); 146 mus::ScopedWindowPtr::DeleteWindowOrWindowManager(root_);
146 else 147 else
147 delete this; 148 delete this;
148 } 149 }
149 150
150 void BrowserWindow::ShowOmnibox() { 151 void BrowserWindow::ShowOmnibox() {
151 TRACE_EVENT0("desktop_ui", "BrowserWindow::ShowOmnibox"); 152 TRACE_EVENT0("desktop_ui", "BrowserWindow::ShowOmnibox");
152 if (!omnibox_.get()) { 153 if (!omnibox_.get()) {
153 omnibox_connection_ = app_->ConnectToApplication("mojo:omnibox"); 154 omnibox_connection_ = shell_->ConnectToApplication("mojo:omnibox");
154 omnibox_connection_->AddService<ViewEmbedder>(this); 155 omnibox_connection_->AddService<ViewEmbedder>(this);
155 omnibox_connection_->ConnectToService(&omnibox_); 156 omnibox_connection_->ConnectToService(&omnibox_);
156 omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler( 157 omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler(
157 [this]() { 158 [this]() {
158 // This will cause the connection to be re-established the next time 159 // This will cause the connection to be re-established the next time
159 // we come through this codepath. 160 // we come through this codepath.
160 omnibox_.reset(); 161 omnibox_.reset();
161 }); 162 });
162 } 163 }
163 omnibox_->ShowForURL(mojo::String::From(current_url_.spec())); 164 omnibox_->ShowForURL(mojo::String::From(current_url_.spec()));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 206
206 content_ = root_->connection()->NewWindow(); 207 content_ = root_->connection()->NewWindow();
207 Init(root_); 208 Init(root_);
208 209
209 host_->SetSize(mojo::Size::From(gfx::Size(1280, 800))); 210 host_->SetSize(mojo::Size::From(gfx::Size(1280, 800)));
210 211
211 root_->AddChild(content_); 212 root_->AddChild(content_);
212 window_manager_client_->AddActivationParent(root_); 213 window_manager_client_->AddActivationParent(root_);
213 content_->SetVisible(true); 214 content_->SetVisible(true);
214 215
215 web_view_.Init(app_, content_); 216 web_view_.Init(shell_, content_);
216 217
217 const base::Callback<void(bool)> add_accelerator_callback = 218 const base::Callback<void(bool)> add_accelerator_callback =
218 base::Bind(&OnAcceleratorAdded); 219 base::Bind(&OnAcceleratorAdded);
219 DCHECK(window_manager_client_); 220 DCHECK(window_manager_client_);
220 window_manager_client_->AddAccelerator( 221 window_manager_client_->AddAccelerator(
221 static_cast<uint32_t>(BrowserCommand::CLOSE), 222 static_cast<uint32_t>(BrowserCommand::CLOSE),
222 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, 223 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W,
223 mus::mojom::kEventFlagControlDown), 224 mus::mojom::kEventFlagControlDown),
224 add_accelerator_callback); 225 add_accelerator_callback);
225 window_manager_client_->AddAccelerator( 226 window_manager_client_->AddAccelerator(
(...skipping 28 matching lines...) Expand all
254 // Record the time spent opening initial tabs, used for performance testing. 255 // Record the time spent opening initial tabs, used for performance testing.
255 const base::TimeDelta open_tabs_delta = 256 const base::TimeDelta open_tabs_delta =
256 base::TimeTicks::Now() - display_ticks; 257 base::TimeTicks::Now() - display_ticks;
257 258
258 // Record the browser startup time metrics, used for performance testing. 259 // Record the browser startup time metrics, used for performance testing.
259 static bool recorded_browser_startup_metrics = false; 260 static bool recorded_browser_startup_metrics = false;
260 if (!recorded_browser_startup_metrics && 261 if (!recorded_browser_startup_metrics &&
261 base::CommandLine::ForCurrentProcess()->HasSwitch( 262 base::CommandLine::ForCurrentProcess()->HasSwitch(
262 tracing::kEnableStatsCollectionBindings)) { 263 tracing::kEnableStatsCollectionBindings)) {
263 tracing::StartupPerformanceDataCollectorPtr collector; 264 tracing::StartupPerformanceDataCollectorPtr collector;
264 app_->ConnectToService("mojo:tracing", &collector); 265 shell_->ConnectToService("mojo:tracing", &collector);
265 collector->SetBrowserWindowDisplayTicks(display_ticks.ToInternalValue()); 266 collector->SetBrowserWindowDisplayTicks(display_ticks.ToInternalValue());
266 collector->SetBrowserOpenTabsTimeDelta(open_tabs_delta.ToInternalValue()); 267 collector->SetBrowserOpenTabsTimeDelta(open_tabs_delta.ToInternalValue());
267 collector->SetBrowserMessageLoopStartTicks( 268 collector->SetBrowserMessageLoopStartTicks(
268 manager_->startup_ticks().ToInternalValue()); 269 manager_->startup_ticks().ToInternalValue());
269 recorded_browser_startup_metrics = true; 270 recorded_browser_startup_metrics = true;
270 } 271 }
271 } 272 }
272 273
273 void BrowserWindow::OnConnectionLost(mus::WindowTreeConnection* connection) { 274 void BrowserWindow::OnConnectionLost(mus::WindowTreeConnection* connection) {
274 root_ = nullptr; 275 root_ = nullptr;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 web_view_.web_view()->StopFinding(); 409 web_view_.web_view()->StopFinding();
409 } 410 }
410 411
411 //////////////////////////////////////////////////////////////////////////////// 412 ////////////////////////////////////////////////////////////////////////////////
412 // BrowserWindow, private: 413 // BrowserWindow, private:
413 414
414 void BrowserWindow::Init(mus::Window* root) { 415 void BrowserWindow::Init(mus::Window* root) {
415 DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0); 416 DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0);
416 if (!aura_init_) { 417 if (!aura_init_) {
417 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root))); 418 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root)));
418 aura_init_.reset(new views::AuraInit(app_, "mandoline_ui.pak")); 419 aura_init_.reset(new views::AuraInit(shell_, "mandoline_ui.pak"));
419 } 420 }
420 421
421 root_ = root; 422 root_ = root;
422 omnibox_view_ = root_->connection()->NewWindow(); 423 omnibox_view_ = root_->connection()->NewWindow();
423 root_->AddChild(omnibox_view_); 424 root_->AddChild(omnibox_view_);
424 425
425 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; 426 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
426 widget_delegate->GetContentsView()->set_background( 427 widget_delegate->GetContentsView()->set_background(
427 views::Background::CreateSolidBackground(0xFFDDDDDD)); 428 views::Background::CreateSolidBackground(0xFFDDDDDD));
428 toolbar_view_ = new ToolbarView(this); 429 toolbar_view_ = new ToolbarView(this);
429 progress_bar_ = new ProgressView; 430 progress_bar_ = new ProgressView;
430 widget_delegate->GetContentsView()->AddChildView(toolbar_view_); 431 widget_delegate->GetContentsView()->AddChildView(toolbar_view_);
431 widget_delegate->GetContentsView()->AddChildView(progress_bar_); 432 widget_delegate->GetContentsView()->AddChildView(progress_bar_);
432 widget_delegate->GetContentsView()->SetLayoutManager( 433 widget_delegate->GetContentsView()->SetLayoutManager(
433 new LayoutManagerImpl(this)); 434 new LayoutManagerImpl(this));
434 435
435 find_bar_view_ = new FindBarView(this); 436 find_bar_view_ = new FindBarView(this);
436 widget_delegate->GetContentsView()->AddChildView(find_bar_view_); 437 widget_delegate->GetContentsView()->AddChildView(find_bar_view_);
437 438
438 views::Widget* widget = new views::Widget; 439 views::Widget* widget = new views::Widget;
439 views::Widget::InitParams params( 440 views::Widget::InitParams params(
440 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 441 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
441 params.native_widget = new views::NativeWidgetMus( 442 params.native_widget = new views::NativeWidgetMus(
442 widget, app_->shell(), root, mus::mojom::SurfaceType::DEFAULT); 443 widget, shell_, root, mus::mojom::SurfaceType::DEFAULT);
443 params.delegate = widget_delegate; 444 params.delegate = widget_delegate;
444 params.bounds = root_->bounds(); 445 params.bounds = root_->bounds();
445 widget->Init(params); 446 widget->Init(params);
446 widget->Show(); 447 widget->Show();
447 root_->SetFocus(); 448 root_->SetFocus();
448 } 449 }
449 450
450 void BrowserWindow::EmbedOmnibox() { 451 void BrowserWindow::EmbedOmnibox() {
451 mus::mojom::WindowTreeClientPtr view_tree_client; 452 mus::mojom::WindowTreeClientPtr view_tree_client;
452 omnibox_->GetWindowTreeClient(GetProxy(&view_tree_client)); 453 omnibox_->GetWindowTreeClient(GetProxy(&view_tree_client));
(...skipping 29 matching lines...) Expand all
482 content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width())); 483 content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width()));
483 content_bounds.set_height(host->bounds().height() - content_bounds.y() - 484 content_bounds.set_height(host->bounds().height() - content_bounds.y() -
484 DIPSToPixels(10)); 485 DIPSToPixels(10));
485 content_->SetBounds(content_bounds); 486 content_->SetBounds(content_bounds);
486 487
487 // The omnibox view bounds are in physical pixels. 488 // The omnibox view bounds are in physical pixels.
488 omnibox_view_->SetBounds(bounds_in_physical_pixels); 489 omnibox_view_->SetBounds(bounds_in_physical_pixels);
489 } 490 }
490 491
491 } // namespace mandoline 492 } // namespace mandoline
OLDNEW
« no previous file with comments | « mandoline/ui/desktop_ui/browser_window.h ('k') | mandoline/ui/omnibox/omnibox_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698