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

Side by Side Diff: mandoline/ui/browser/browser.cc

Issue 1136593004: Add a simple browser UI (with url bar) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 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/browser/browser.h ('k') | mandoline/ui/browser/browser_ui.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/browser/browser.h" 5 #include "mandoline/ui/browser/browser.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "mandoline/ui/browser/browser_ui.h"
9 #include "mandoline/ui/browser/merged_service_provider.h" 10 #include "mandoline/ui/browser/merged_service_provider.h"
11 #include "mojo/application/application_runner_chromium.h"
12 #include "third_party/mojo/src/mojo/public/c/system/main.h"
10 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
11 14
12 namespace mandoline { 15 namespace mandoline {
13 16
14 Browser::Browser() 17 Browser::Browser()
15 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), 18 : window_manager_app_(new window_manager::WindowManagerApp(this, this)),
16 root_(nullptr), 19 root_(nullptr),
17 content_(nullptr), 20 content_(nullptr),
18 navigator_host_(this), 21 navigator_host_(this),
22 ui_(nullptr),
19 weak_factory_(this) { 23 weak_factory_(this) {
20 exposed_services_impl_.AddService(this); 24 exposed_services_impl_.AddService(this);
21 } 25 }
22 26
23 Browser::~Browser() { 27 Browser::~Browser() {
24 } 28 }
25 29
26 base::WeakPtr<Browser> Browser::GetWeakPtr() { 30 base::WeakPtr<Browser> Browser::GetWeakPtr() {
27 return weak_factory_.GetWeakPtr(); 31 return weak_factory_.GetWeakPtr();
28 } 32 }
29 33
30 void Browser::Initialize(mojo::ApplicationImpl* app) { 34 void Browser::Initialize(mojo::ApplicationImpl* app) {
31 window_manager_app_->Initialize(app); 35 window_manager_app_->Initialize(app);
36 ui_.reset(BrowserUI::Create(this, app->shell()));
32 37
33 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 38 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
34 base::CommandLine::StringVector args = command_line->GetArgs(); 39 base::CommandLine::StringVector args = command_line->GetArgs();
35 if (args.empty()) { 40 if (args.empty()) {
36 default_url_ = "http://www.google.com/"; 41 default_url_ = "http://www.google.com/";
37 } else { 42 } else {
38 #if defined(OS_WIN) 43 #if defined(OS_WIN)
39 default_url_ = base::WideToUTF8(args[0]); 44 default_url_ = base::WideToUTF8(args[0]);
40 #else 45 #else
41 default_url_ = args[0]; 46 default_url_ = args[0];
(...skipping 13 matching lines...) Expand all
55 return true; 60 return true;
56 } 61 }
57 62
58 void Browser::OnEmbed( 63 void Browser::OnEmbed(
59 mojo::View* root, 64 mojo::View* root,
60 mojo::InterfaceRequest<mojo::ServiceProvider> services, 65 mojo::InterfaceRequest<mojo::ServiceProvider> services,
61 mojo::ServiceProviderPtr exposed_services) { 66 mojo::ServiceProviderPtr exposed_services) {
62 // Browser does not support being embedded more than once. 67 // Browser does not support being embedded more than once.
63 CHECK(!root_); 68 CHECK(!root_);
64 69
70 // TODO(beng): still unhappy with the fact that both this class & the UI class
71 // know so much about these views. Figure out how to shift more to
72 // the UI class.
65 root_ = root; 73 root_ = root;
66 root_->AddObserver(this); 74 content_ = root->view_manager()->CreateView();
75 ui_->Init(root_, content_);
67 76
68 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
69 // Resize to match the Nexus 5 aspect ratio: 78 // Resize to match the Nexus 5 aspect ratio:
70 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); 79 window_manager_app_->SetViewportSize(gfx::Size(320, 640));
71 #else 80 #else
72 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); 81 window_manager_app_->SetViewportSize(gfx::Size(1280, 800));
73 #endif 82 #endif
74 83
75 content_ = root->view_manager()->CreateView();
76 content_->SetBounds(root_->bounds());
77 root_->AddChild(content_); 84 root_->AddChild(content_);
78 content_->SetVisible(true); 85 content_->SetVisible(true);
79 86
80 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, 87 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK,
81 mojo::EVENT_FLAGS_NONE); 88 mojo::EVENT_FLAGS_NONE);
82 89
83 // Now that we're ready, either load a pending url or the default url. 90 // Now that we're ready, either load a pending url or the default url.
84 if (!pending_url_.empty()) 91 if (!pending_url_.empty())
85 Embed(pending_url_, services.Pass(), exposed_services.Pass()); 92 Embed(pending_url_, services.Pass(), exposed_services.Pass());
86 else if (!default_url_.empty()) 93 else if (!default_url_.empty())
(...skipping 29 matching lines...) Expand all
116 void Browser::Create(mojo::ApplicationConnection* connection, 123 void Browser::Create(mojo::ApplicationConnection* connection,
117 mojo::InterfaceRequest<mojo::NavigatorHost> request) { 124 mojo::InterfaceRequest<mojo::NavigatorHost> request) {
118 navigator_host_.Bind(request.Pass()); 125 navigator_host_.Bind(request.Pass());
119 } 126 }
120 127
121 void Browser::OnViewManagerDisconnected( 128 void Browser::OnViewManagerDisconnected(
122 mojo::ViewManager* view_manager) { 129 mojo::ViewManager* view_manager) {
123 root_ = nullptr; 130 root_ = nullptr;
124 } 131 }
125 132
126 void Browser::OnViewDestroyed(mojo::View* view) {
127 view->RemoveObserver(this);
128 }
129
130 void Browser::OnViewBoundsChanged(mojo::View* view,
131 const mojo::Rect& old_bounds,
132 const mojo::Rect& new_bounds) {
133 content_->SetBounds(new_bounds);
134 }
135
136 // Convenience method: 133 // Convenience method:
137 void Browser::ReplaceContentWithURL(const mojo::String& url) { 134 void Browser::ReplaceContentWithURL(const mojo::String& url) {
138 Embed(url, nullptr, nullptr); 135 Embed(url, nullptr, nullptr);
139 } 136 }
140 137
141 } // namespace mandoline 138 } // namespace mandoline
OLDNEW
« no previous file with comments | « mandoline/ui/browser/browser.h ('k') | mandoline/ui/browser/browser_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698