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

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

Issue 1371773003: mandoline: Add find in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT to fix patch failure. Created 5 years, 2 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
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/mus/public/cpp/scoped_view_ptr.h" 11 #include "components/mus/public/cpp/scoped_view_ptr.h"
12 #include "components/mus/public/cpp/view_tree_host_factory.h" 12 #include "components/mus/public/cpp/view_tree_host_factory.h"
13 #include "mandoline/ui/aura/native_widget_view_manager.h" 13 #include "mandoline/ui/aura/native_widget_view_manager.h"
14 #include "mandoline/ui/desktop_ui/browser_commands.h" 14 #include "mandoline/ui/desktop_ui/browser_commands.h"
15 #include "mandoline/ui/desktop_ui/browser_manager.h" 15 #include "mandoline/ui/desktop_ui/browser_manager.h"
16 #include "mandoline/ui/desktop_ui/find_bar_view.h"
16 #include "mandoline/ui/desktop_ui/public/interfaces/omnibox.mojom.h" 17 #include "mandoline/ui/desktop_ui/public/interfaces/omnibox.mojom.h"
17 #include "mandoline/ui/desktop_ui/toolbar_view.h" 18 #include "mandoline/ui/desktop_ui/toolbar_view.h"
18 #include "mojo/common/common_type_converters.h" 19 #include "mojo/common/common_type_converters.h"
19 #include "mojo/converters/geometry/geometry_type_converters.h" 20 #include "mojo/converters/geometry/geometry_type_converters.h"
20 #include "mojo/services/tracing/public/cpp/switches.h" 21 #include "mojo/services/tracing/public/cpp/switches.h"
21 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" 22 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h"
22 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
23 #include "ui/views/background.h" 24 #include "ui/views/background.h"
24 #include "ui/views/controls/button/label_button.h" 25 #include "ui/views/controls/button/label_button.h"
25 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // BrowserWindow, public: 68 // BrowserWindow, public:
68 69
69 BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app, 70 BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app,
70 mojo::ViewTreeHostFactory* host_factory, 71 mojo::ViewTreeHostFactory* host_factory,
71 BrowserManager* manager) 72 BrowserManager* manager)
72 : app_(app), 73 : app_(app),
73 host_client_binding_(this), 74 host_client_binding_(this),
74 manager_(manager), 75 manager_(manager),
75 toolbar_view_(nullptr), 76 toolbar_view_(nullptr),
76 progress_bar_(nullptr), 77 progress_bar_(nullptr),
78 find_bar_view_(nullptr),
77 root_(nullptr), 79 root_(nullptr),
78 content_(nullptr), 80 content_(nullptr),
79 omnibox_view_(nullptr), 81 omnibox_view_(nullptr),
82 find_active_(0),
83 find_count_(0),
80 web_view_(this) { 84 web_view_(this) {
81 mojo::ViewTreeHostClientPtr host_client; 85 mojo::ViewTreeHostClientPtr host_client;
82 host_client_binding_.Bind(GetProxy(&host_client)); 86 host_client_binding_.Bind(GetProxy(&host_client));
83 mus::CreateViewTreeHost(host_factory, host_client.Pass(), this, &host_); 87 mus::CreateViewTreeHost(host_factory, host_client.Pass(), this, &host_);
84 } 88 }
85 89
86 void BrowserWindow::LoadURL(const GURL& url) { 90 void BrowserWindow::LoadURL(const GURL& url) {
87 // Haven't been embedded yet, can't embed. 91 // Haven't been embedded yet, can't embed.
88 // TODO(beng): remove this. 92 // TODO(beng): remove this.
89 if (!root_) { 93 if (!root_) {
(...skipping 28 matching lines...) Expand all
118 omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler( 122 omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler(
119 [this]() { 123 [this]() {
120 // This will cause the connection to be re-established the next time 124 // This will cause the connection to be re-established the next time
121 // we come through this codepath. 125 // we come through this codepath.
122 omnibox_.reset(); 126 omnibox_.reset();
123 }); 127 });
124 } 128 }
125 omnibox_->ShowForURL(mojo::String::From(current_url_.spec())); 129 omnibox_->ShowForURL(mojo::String::From(current_url_.spec()));
126 } 130 }
127 131
132 void BrowserWindow::ShowFind() {
133 toolbar_view_->SetVisible(false);
134 find_bar_view_->Show();
135 }
136
128 void BrowserWindow::GoBack() { 137 void BrowserWindow::GoBack() {
129 web_view_.web_view()->GoBack(); 138 web_view_.web_view()->GoBack();
130 } 139 }
131 140
132 void BrowserWindow::GoForward() { 141 void BrowserWindow::GoForward() {
133 web_view_.web_view()->GoForward(); 142 web_view_.web_view()->GoForward();
134 } 143 }
135 144
136 BrowserWindow::~BrowserWindow() { 145 BrowserWindow::~BrowserWindow() {
137 DCHECK(!root_); 146 DCHECK(!root_);
(...skipping 27 matching lines...) Expand all
165 content_->SetVisible(true); 174 content_->SetVisible(true);
166 175
167 web_view_.Init(app_, content_); 176 web_view_.Init(app_, content_);
168 177
169 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::CLOSE), 178 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::CLOSE),
170 mojo::KEYBOARD_CODE_W, mojo::EVENT_FLAGS_CONTROL_DOWN); 179 mojo::KEYBOARD_CODE_W, mojo::EVENT_FLAGS_CONTROL_DOWN);
171 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::FOCUS_OMNIBOX), 180 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::FOCUS_OMNIBOX),
172 mojo::KEYBOARD_CODE_L, mojo::EVENT_FLAGS_CONTROL_DOWN); 181 mojo::KEYBOARD_CODE_L, mojo::EVENT_FLAGS_CONTROL_DOWN);
173 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::NEW_WINDOW), 182 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::NEW_WINDOW),
174 mojo::KEYBOARD_CODE_N, mojo::EVENT_FLAGS_CONTROL_DOWN); 183 mojo::KEYBOARD_CODE_N, mojo::EVENT_FLAGS_CONTROL_DOWN);
184 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::SHOW_FIND),
185 mojo::KEYBOARD_CODE_F, mojo::EVENT_FLAGS_CONTROL_DOWN);
175 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_BACK), 186 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_BACK),
176 mojo::KEYBOARD_CODE_LEFT, mojo::EVENT_FLAGS_ALT_DOWN); 187 mojo::KEYBOARD_CODE_LEFT, mojo::EVENT_FLAGS_ALT_DOWN);
177 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_FORWARD), 188 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_FORWARD),
178 mojo::KEYBOARD_CODE_RIGHT, mojo::EVENT_FLAGS_ALT_DOWN); 189 mojo::KEYBOARD_CODE_RIGHT, mojo::EVENT_FLAGS_ALT_DOWN);
179 190
180 // Now that we're ready, load the default url. 191 // Now that we're ready, load the default url.
181 LoadURL(default_url_); 192 LoadURL(default_url_);
182 193
183 // Record the time spent opening initial tabs, used for performance testing. 194 // Record the time spent opening initial tabs, used for performance testing.
184 const base::TimeDelta open_tabs_delta = base::Time::Now() - display_time; 195 const base::TimeDelta open_tabs_delta = base::Time::Now() - display_time;
(...skipping 27 matching lines...) Expand all
212 switch (static_cast<BrowserCommand>(id)) { 223 switch (static_cast<BrowserCommand>(id)) {
213 case BrowserCommand::CLOSE: 224 case BrowserCommand::CLOSE:
214 Close(); 225 Close();
215 break; 226 break;
216 case BrowserCommand::NEW_WINDOW: 227 case BrowserCommand::NEW_WINDOW:
217 manager_->CreateBrowser(GURL()); 228 manager_->CreateBrowser(GURL());
218 break; 229 break;
219 case BrowserCommand::FOCUS_OMNIBOX: 230 case BrowserCommand::FOCUS_OMNIBOX:
220 ShowOmnibox(); 231 ShowOmnibox();
221 break; 232 break;
233 case BrowserCommand::SHOW_FIND:
234 ShowFind();
235 break;
222 case BrowserCommand::GO_BACK: 236 case BrowserCommand::GO_BACK:
223 GoBack(); 237 GoBack();
224 break; 238 break;
225 case BrowserCommand::GO_FORWARD: 239 case BrowserCommand::GO_FORWARD:
226 GoForward(); 240 GoForward();
227 break; 241 break;
228 default: 242 default:
229 NOTREACHED(); 243 NOTREACHED();
230 break; 244 break;
231 } 245 }
232 } 246 }
233 247
234 //////////////////////////////////////////////////////////////////////////////// 248 ////////////////////////////////////////////////////////////////////////////////
235 // BrowserWindow, web_view::mojom::WebViewClient implementation: 249 // BrowserWindow, web_view::mojom::WebViewClient implementation:
236 250
237 void BrowserWindow::TopLevelNavigateRequest(mojo::URLRequestPtr request) { 251 void BrowserWindow::TopLevelNavigateRequest(mojo::URLRequestPtr request) {
252 OnHideFindBar();
238 Embed(request.Pass()); 253 Embed(request.Pass());
239 } 254 }
240 255
241 void BrowserWindow::TopLevelNavigationStarted(const mojo::String& url) { 256 void BrowserWindow::TopLevelNavigationStarted(const mojo::String& url) {
242 GURL gurl(url); 257 GURL gurl(url);
243 bool changed = current_url_ != gurl; 258 bool changed = current_url_ != gurl;
244 current_url_ = gurl; 259 current_url_ = gurl;
245 if (changed) 260 if (changed)
246 toolbar_view_->SetOmniboxText(base::UTF8ToUTF16(current_url_.spec())); 261 toolbar_view_->SetOmniboxText(base::UTF8ToUTF16(current_url_.spec()));
247 } 262 }
(...skipping 12 matching lines...) Expand all
260 } 275 }
261 276
262 void BrowserWindow::TitleChanged(const mojo::String& title) { 277 void BrowserWindow::TitleChanged(const mojo::String& title) {
263 base::string16 formatted = 278 base::string16 formatted =
264 title.is_null() ? base::ASCIIToUTF16("Untitled") 279 title.is_null() ? base::ASCIIToUTF16("Untitled")
265 : title.To<base::string16>() + 280 : title.To<base::string16>() +
266 base::ASCIIToUTF16(" - Mandoline"); 281 base::ASCIIToUTF16(" - Mandoline");
267 host_->SetTitle(mojo::String::From(formatted)); 282 host_->SetTitle(mojo::String::From(formatted));
268 } 283 }
269 284
285 void BrowserWindow::ReportFindInPageMatchCount(int32_t request_id,
286 int32_t count,
287 bool final_update) {
288 find_count_ = count;
289 find_bar_view_->SetMatchLabel(find_active_, find_count_);
290 }
291
292 void BrowserWindow::ReportFindInPageSelection(
293 int32_t request_id,
294 int32_t active_match_ordinal) {
295 find_active_ = active_match_ordinal;
296 find_bar_view_->SetMatchLabel(find_active_, find_count_);
297 }
298
270 //////////////////////////////////////////////////////////////////////////////// 299 ////////////////////////////////////////////////////////////////////////////////
271 // BrowserWindow, ViewEmbedder implementation: 300 // BrowserWindow, ViewEmbedder implementation:
272 301
273 void BrowserWindow::Embed(mojo::URLRequestPtr request) { 302 void BrowserWindow::Embed(mojo::URLRequestPtr request) {
274 const std::string string_url = request->url.To<std::string>(); 303 const std::string string_url = request->url.To<std::string>();
275 if (string_url == "mojo:omnibox") { 304 if (string_url == "mojo:omnibox") {
276 EmbedOmnibox(); 305 EmbedOmnibox();
277 return; 306 return;
278 } 307 }
279 web_view_.web_view()->LoadRequest(request.Pass()); 308 web_view_.web_view()->LoadRequest(request.Pass());
(...skipping 18 matching lines...) Expand all
298 // TODO(fsamuel): All bounds should be in physical pixels. 327 // TODO(fsamuel): All bounds should be in physical pixels.
299 gfx::Rect bounds_in_physical_pixels(host->bounds()); 328 gfx::Rect bounds_in_physical_pixels(host->bounds());
300 float inverse_device_pixel_ratio = 329 float inverse_device_pixel_ratio =
301 1.0f / root_->viewport_metrics().device_pixel_ratio; 330 1.0f / root_->viewport_metrics().device_pixel_ratio;
302 331
303 gfx::Rect toolbar_bounds = gfx::ScaleToEnclosingRect( 332 gfx::Rect toolbar_bounds = gfx::ScaleToEnclosingRect(
304 bounds_in_physical_pixels, inverse_device_pixel_ratio); 333 bounds_in_physical_pixels, inverse_device_pixel_ratio);
305 toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40); 334 toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40);
306 toolbar_view_->SetBoundsRect(toolbar_bounds); 335 toolbar_view_->SetBoundsRect(toolbar_bounds);
307 336
337 find_bar_view_->SetBoundsRect(toolbar_bounds);
338
308 gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2, 339 gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2,
309 toolbar_bounds.width(), 5); 340 toolbar_bounds.width(), 5);
310 341
311 // The content view bounds are in physical pixels. 342 // The content view bounds are in physical pixels.
312 mojo::Rect content_bounds_mojo; 343 mojo::Rect content_bounds_mojo;
313 content_bounds_mojo.x = DIPSToPixels(progress_bar_bounds.x()); 344 content_bounds_mojo.x = DIPSToPixels(progress_bar_bounds.x());
314 content_bounds_mojo.y = DIPSToPixels(progress_bar_bounds.bottom()+ 10); 345 content_bounds_mojo.y = DIPSToPixels(progress_bar_bounds.bottom()+ 10);
315 content_bounds_mojo.width = DIPSToPixels(progress_bar_bounds.width()); 346 content_bounds_mojo.width = DIPSToPixels(progress_bar_bounds.width());
316 content_bounds_mojo.height = 347 content_bounds_mojo.height =
317 host->bounds().height() - content_bounds_mojo.y - DIPSToPixels(10); 348 host->bounds().height() - content_bounds_mojo.y - DIPSToPixels(10);
318 content_->SetBounds(content_bounds_mojo); 349 content_->SetBounds(content_bounds_mojo);
319 350
320 // The omnibox view bounds are in physical pixels. 351 // The omnibox view bounds are in physical pixels.
321 omnibox_view_->SetBounds( 352 omnibox_view_->SetBounds(
322 mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert( 353 mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert(
323 bounds_in_physical_pixels)); 354 bounds_in_physical_pixels));
324 } 355 }
325 356
326 //////////////////////////////////////////////////////////////////////////////// 357 ////////////////////////////////////////////////////////////////////////////////
358 // BrowserWindow, FindBarDelegate implementation:
359
360 void BrowserWindow::OnDoFind(const std::string& find) {
361 static int find_id = 0;
362 web_view_.web_view()->Find(++find_id, mojo::String::From(find));
363 }
364
365 void BrowserWindow::OnHideFindBar() {
366 toolbar_view_->SetVisible(true);
367 find_bar_view_->Hide();
368 web_view_.web_view()->StopFinding();
369 }
370
371 ////////////////////////////////////////////////////////////////////////////////
327 // BrowserWindow, private: 372 // BrowserWindow, private:
328 373
329 void BrowserWindow::Init(mus::View* root) { 374 void BrowserWindow::Init(mus::View* root) {
330 DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0); 375 DCHECK_GT(root->viewport_metrics().device_pixel_ratio, 0);
331 if (!aura_init_) 376 if (!aura_init_)
332 aura_init_.reset(new AuraInit(root, app_->shell())); 377 aura_init_.reset(new AuraInit(root, app_->shell()));
333 378
334 root_ = root; 379 root_ = root;
335 omnibox_view_ = root_->connection()->CreateView(); 380 omnibox_view_ = root_->connection()->CreateView();
336 root_->AddChild(omnibox_view_); 381 root_->AddChild(omnibox_view_);
337 382
338 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; 383 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
339 widget_delegate->GetContentsView()->set_background( 384 widget_delegate->GetContentsView()->set_background(
340 views::Background::CreateSolidBackground(0xFFDDDDDD)); 385 views::Background::CreateSolidBackground(0xFFDDDDDD));
341 toolbar_view_ = new ToolbarView(this); 386 toolbar_view_ = new ToolbarView(this);
342 progress_bar_ = new ProgressView; 387 progress_bar_ = new ProgressView;
343 widget_delegate->GetContentsView()->AddChildView(toolbar_view_); 388 widget_delegate->GetContentsView()->AddChildView(toolbar_view_);
344 widget_delegate->GetContentsView()->AddChildView(progress_bar_); 389 widget_delegate->GetContentsView()->AddChildView(progress_bar_);
345 widget_delegate->GetContentsView()->SetLayoutManager(this); 390 widget_delegate->GetContentsView()->SetLayoutManager(this);
346 391
392 find_bar_view_ = new FindBarView(this);
393 widget_delegate->GetContentsView()->AddChildView(find_bar_view_);
394
347 views::Widget* widget = new views::Widget; 395 views::Widget* widget = new views::Widget;
348 views::Widget::InitParams params( 396 views::Widget::InitParams params(
349 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 397 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
350 params.native_widget = 398 params.native_widget =
351 new NativeWidgetViewManager(widget, app_->shell(), root_); 399 new NativeWidgetViewManager(widget, app_->shell(), root_);
352 params.delegate = widget_delegate; 400 params.delegate = widget_delegate;
353 params.bounds = root_->bounds().To<gfx::Rect>(); 401 params.bounds = root_->bounds().To<gfx::Rect>();
354 widget->Init(params); 402 widget->Init(params);
355 widget->Show(); 403 widget->Show();
356 root_->SetFocus(); 404 root_->SetFocus();
357 } 405 }
358 406
359 void BrowserWindow::EmbedOmnibox() { 407 void BrowserWindow::EmbedOmnibox() {
360 mojo::ViewTreeClientPtr view_tree_client; 408 mojo::ViewTreeClientPtr view_tree_client;
361 omnibox_->GetViewTreeClient(GetProxy(&view_tree_client)); 409 omnibox_->GetViewTreeClient(GetProxy(&view_tree_client));
362 omnibox_view_->Embed(view_tree_client.Pass()); 410 omnibox_view_->Embed(view_tree_client.Pass());
363 411
364 // TODO(beng): This should be handled sufficiently by 412 // TODO(beng): This should be handled sufficiently by
365 // OmniboxImpl::ShowWindow() but unfortunately view manager policy 413 // OmniboxImpl::ShowWindow() but unfortunately view manager policy
366 // currently prevents the embedded app from changing window z for 414 // currently prevents the embedded app from changing window z for
367 // its own window. 415 // its own window.
368 omnibox_view_->MoveToFront(); 416 omnibox_view_->MoveToFront();
369 } 417 }
370 418
371 } // namespace mandoline 419 } // namespace mandoline
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698