| OLD | NEW |
| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "ui/mojo/init/ui_init.h" | 30 #include "ui/mojo/init/ui_init.h" |
| 31 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
| 32 #include "ui/views/controls/button/label_button.h" | 32 #include "ui/views/controls/button/label_button.h" |
| 33 #include "ui/views/layout/layout_manager.h" | 33 #include "ui/views/layout/layout_manager.h" |
| 34 #include "ui/views/mus/aura_init.h" | 34 #include "ui/views/mus/aura_init.h" |
| 35 #include "ui/views/mus/display_converter.h" | 35 #include "ui/views/mus/display_converter.h" |
| 36 #include "ui/views/mus/native_widget_mus.h" | 36 #include "ui/views/mus/native_widget_mus.h" |
| 37 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
| 38 | 38 |
| 39 namespace mandoline { | 39 namespace mandoline { |
| 40 namespace { |
| 41 |
| 42 void OnAcceleratorAdded(bool success) { |
| 43 DCHECK(success); |
| 44 } |
| 45 |
| 46 } // namespace |
| 40 | 47 |
| 41 class ProgressView : public views::View { | 48 class ProgressView : public views::View { |
| 42 public: | 49 public: |
| 43 ProgressView() : progress_(0.f), loading_(false) {} | 50 ProgressView() : progress_(0.f), loading_(false) {} |
| 44 ~ProgressView() override {} | 51 ~ProgressView() override {} |
| 45 | 52 |
| 46 void SetProgress(double progress) { | 53 void SetProgress(double progress) { |
| 47 progress_ = progress; | 54 progress_ = progress; |
| 48 SchedulePaint(); | 55 SchedulePaint(); |
| 49 } | 56 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl); | 101 DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl); |
| 95 }; | 102 }; |
| 96 | 103 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
| 98 // BrowserWindow, public: | 105 // BrowserWindow, public: |
| 99 | 106 |
| 100 BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app, | 107 BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app, |
| 101 mus::mojom::WindowTreeHostFactory* host_factory, | 108 mus::mojom::WindowTreeHostFactory* host_factory, |
| 102 BrowserManager* manager) | 109 BrowserManager* manager) |
| 103 : app_(app), | 110 : app_(app), |
| 104 host_client_binding_(this), | 111 window_manager_client_(nullptr), |
| 105 manager_(manager), | 112 manager_(manager), |
| 106 toolbar_view_(nullptr), | 113 toolbar_view_(nullptr), |
| 107 progress_bar_(nullptr), | 114 progress_bar_(nullptr), |
| 108 find_bar_view_(nullptr), | 115 find_bar_view_(nullptr), |
| 109 root_(nullptr), | 116 root_(nullptr), |
| 110 content_(nullptr), | 117 content_(nullptr), |
| 111 omnibox_view_(nullptr), | 118 omnibox_view_(nullptr), |
| 112 find_active_(0), | 119 find_active_(0), |
| 113 find_count_(0), | 120 find_count_(0), |
| 114 web_view_(this) { | 121 web_view_(this) { |
| 115 mus::CreateWindowTreeHost(host_factory, | 122 mus::CreateWindowTreeHost(host_factory, nullptr, this, &host_, this); |
| 116 host_client_binding_.CreateInterfacePtrAndBind(), | |
| 117 this, &host_, nullptr); | |
| 118 } | 123 } |
| 119 | 124 |
| 120 void BrowserWindow::LoadURL(const GURL& url) { | 125 void BrowserWindow::LoadURL(const GURL& url) { |
| 121 // Haven't been embedded yet, can't embed. | 126 // Haven't been embedded yet, can't embed. |
| 122 // TODO(beng): remove this. | 127 // TODO(beng): remove this. |
| 123 if (!root_) { | 128 if (!root_) { |
| 124 default_url_ = url; | 129 default_url_ = url; |
| 125 return; | 130 return; |
| 126 } | 131 } |
| 127 | 132 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 Init(root_); | 207 Init(root_); |
| 203 | 208 |
| 204 host_->SetSize(mojo::Size::From(gfx::Size(1280, 800))); | 209 host_->SetSize(mojo::Size::From(gfx::Size(1280, 800))); |
| 205 | 210 |
| 206 root_->AddChild(content_); | 211 root_->AddChild(content_); |
| 207 host_->AddActivationParent(root_->id()); | 212 host_->AddActivationParent(root_->id()); |
| 208 content_->SetVisible(true); | 213 content_->SetVisible(true); |
| 209 | 214 |
| 210 web_view_.Init(app_, content_); | 215 web_view_.Init(app_, content_); |
| 211 | 216 |
| 212 host_->AddAccelerator( | 217 const base::Callback<void(bool)> add_accelerator_callback = |
| 218 base::Bind(&OnAcceleratorAdded); |
| 219 DCHECK(window_manager_client_); |
| 220 window_manager_client_->AddAccelerator( |
| 213 static_cast<uint32_t>(BrowserCommand::CLOSE), | 221 static_cast<uint32_t>(BrowserCommand::CLOSE), |
| 214 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, | 222 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::W, |
| 215 mus::mojom::kEventFlagControlDown), | 223 mus::mojom::kEventFlagControlDown), |
| 216 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 224 add_accelerator_callback); |
| 217 host_->AddAccelerator( | 225 window_manager_client_->AddAccelerator( |
| 218 static_cast<uint32_t>(BrowserCommand::FOCUS_OMNIBOX), | 226 static_cast<uint32_t>(BrowserCommand::FOCUS_OMNIBOX), |
| 219 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::L, | 227 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::L, |
| 220 mus::mojom::kEventFlagControlDown), | 228 mus::mojom::kEventFlagControlDown), |
| 221 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 229 add_accelerator_callback); |
| 222 host_->AddAccelerator( | 230 window_manager_client_->AddAccelerator( |
| 223 static_cast<uint32_t>(BrowserCommand::NEW_WINDOW), | 231 static_cast<uint32_t>(BrowserCommand::NEW_WINDOW), |
| 224 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::N, | 232 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::N, |
| 225 mus::mojom::kEventFlagControlDown), | 233 mus::mojom::kEventFlagControlDown), |
| 226 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 234 add_accelerator_callback); |
| 227 host_->AddAccelerator( | 235 window_manager_client_->AddAccelerator( |
| 228 static_cast<uint32_t>(BrowserCommand::SHOW_FIND), | 236 static_cast<uint32_t>(BrowserCommand::SHOW_FIND), |
| 229 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::F, | 237 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::F, |
| 230 mus::mojom::kEventFlagControlDown), | 238 mus::mojom::kEventFlagControlDown), |
| 231 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 239 add_accelerator_callback); |
| 232 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_BACK), | 240 window_manager_client_->AddAccelerator( |
| 233 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::LEFT, | 241 static_cast<uint32_t>(BrowserCommand::GO_BACK), |
| 234 mus::mojom::kEventFlagAltDown), | 242 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::LEFT, |
| 235 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 243 mus::mojom::kEventFlagAltDown), |
| 236 host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_FORWARD), | 244 add_accelerator_callback); |
| 237 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::RIGHT, | 245 window_manager_client_->AddAccelerator( |
| 238 mus::mojom::kEventFlagAltDown), | 246 static_cast<uint32_t>(BrowserCommand::GO_FORWARD), |
| 239 mus::mojom::WindowTreeHost::AddAcceleratorCallback()); | 247 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::RIGHT, |
| 248 mus::mojom::kEventFlagAltDown), |
| 249 add_accelerator_callback); |
| 250 |
| 240 // Now that we're ready, load the default url. | 251 // Now that we're ready, load the default url. |
| 241 LoadURL(default_url_); | 252 LoadURL(default_url_); |
| 242 | 253 |
| 243 // Record the time spent opening initial tabs, used for performance testing. | 254 // Record the time spent opening initial tabs, used for performance testing. |
| 244 const base::TimeDelta open_tabs_delta = | 255 const base::TimeDelta open_tabs_delta = |
| 245 base::TimeTicks::Now() - display_ticks; | 256 base::TimeTicks::Now() - display_ticks; |
| 246 | 257 |
| 247 // Record the browser startup time metrics, used for performance testing. | 258 // Record the browser startup time metrics, used for performance testing. |
| 248 static bool recorded_browser_startup_metrics = false; | 259 static bool recorded_browser_startup_metrics = false; |
| 249 if (!recorded_browser_startup_metrics && | 260 if (!recorded_browser_startup_metrics && |
| 250 base::CommandLine::ForCurrentProcess()->HasSwitch( | 261 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 251 tracing::kEnableStatsCollectionBindings)) { | 262 tracing::kEnableStatsCollectionBindings)) { |
| 252 tracing::StartupPerformanceDataCollectorPtr collector; | 263 tracing::StartupPerformanceDataCollectorPtr collector; |
| 253 app_->ConnectToService("mojo:tracing", &collector); | 264 app_->ConnectToService("mojo:tracing", &collector); |
| 254 collector->SetBrowserWindowDisplayTicks(display_ticks.ToInternalValue()); | 265 collector->SetBrowserWindowDisplayTicks(display_ticks.ToInternalValue()); |
| 255 collector->SetBrowserOpenTabsTimeDelta(open_tabs_delta.ToInternalValue()); | 266 collector->SetBrowserOpenTabsTimeDelta(open_tabs_delta.ToInternalValue()); |
| 256 collector->SetBrowserMessageLoopStartTicks( | 267 collector->SetBrowserMessageLoopStartTicks( |
| 257 manager_->startup_ticks().ToInternalValue()); | 268 manager_->startup_ticks().ToInternalValue()); |
| 258 recorded_browser_startup_metrics = true; | 269 recorded_browser_startup_metrics = true; |
| 259 } | 270 } |
| 260 } | 271 } |
| 261 | 272 |
| 262 void BrowserWindow::OnConnectionLost(mus::WindowTreeConnection* connection) { | 273 void BrowserWindow::OnConnectionLost(mus::WindowTreeConnection* connection) { |
| 263 root_ = nullptr; | 274 root_ = nullptr; |
| 264 delete this; | 275 delete this; |
| 265 } | 276 } |
| 266 | 277 |
| 267 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
| 268 // BrowserWindow, mus::ViewTreeHostClient implementation: | 279 // BrowserWindow, mus::WindowManagerDelegate implementation: |
| 280 |
| 281 void BrowserWindow::SetWindowManagerClient(mus::WindowManagerClient* client) { |
| 282 window_manager_client_ = client; |
| 283 } |
| 284 |
| 285 bool BrowserWindow::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { |
| 286 return true; |
| 287 } |
| 288 |
| 289 bool BrowserWindow::OnWmSetProperty( |
| 290 mus::Window* window, |
| 291 const std::string& name, |
| 292 scoped_ptr<std::vector<uint8_t>>* new_data) { |
| 293 return true; |
| 294 } |
| 295 |
| 296 mus::Window* BrowserWindow::OnWmCreateTopLevelWindow( |
| 297 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 298 NOTREACHED(); |
| 299 return nullptr; |
| 300 } |
| 269 | 301 |
| 270 void BrowserWindow::OnAccelerator(uint32_t id, mus::mojom::EventPtr event) { | 302 void BrowserWindow::OnAccelerator(uint32_t id, mus::mojom::EventPtr event) { |
| 271 switch (static_cast<BrowserCommand>(id)) { | 303 switch (static_cast<BrowserCommand>(id)) { |
| 272 case BrowserCommand::CLOSE: | 304 case BrowserCommand::CLOSE: |
| 273 Close(); | 305 Close(); |
| 274 break; | 306 break; |
| 275 case BrowserCommand::NEW_WINDOW: | 307 case BrowserCommand::NEW_WINDOW: |
| 276 manager_->CreateBrowser(GURL()); | 308 manager_->CreateBrowser(GURL()); |
| 277 break; | 309 break; |
| 278 case BrowserCommand::FOCUS_OMNIBOX: | 310 case BrowserCommand::FOCUS_OMNIBOX: |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width())); | 482 content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width())); |
| 451 content_bounds.set_height(host->bounds().height() - content_bounds.y() - | 483 content_bounds.set_height(host->bounds().height() - content_bounds.y() - |
| 452 DIPSToPixels(10)); | 484 DIPSToPixels(10)); |
| 453 content_->SetBounds(content_bounds); | 485 content_->SetBounds(content_bounds); |
| 454 | 486 |
| 455 // The omnibox view bounds are in physical pixels. | 487 // The omnibox view bounds are in physical pixels. |
| 456 omnibox_view_->SetBounds(bounds_in_physical_pixels); | 488 omnibox_view_->SetBounds(bounds_in_physical_pixels); |
| 457 } | 489 } |
| 458 | 490 |
| 459 } // namespace mandoline | 491 } // namespace mandoline |
| OLD | NEW |