Chromium Code Reviews| 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/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/mus/public/cpp/window.h" | 14 #include "components/mus/public/cpp/window.h" |
| 15 #include "components/mus/public/cpp/window_tree_client.h" | 15 #include "components/mus/public/cpp/window_tree_client.h" |
| 16 #include "mash/browser/debug_view.h" | |
| 16 #include "mash/public/interfaces/launchable.mojom.h" | 17 #include "mash/public/interfaces/launchable.mojom.h" |
| 17 #include "mojo/public/c/system/main.h" | 18 #include "mojo/public/c/system/main.h" |
| 18 #include "services/navigation/public/interfaces/view.mojom.h" | 19 #include "services/navigation/public/interfaces/view.mojom.h" |
| 19 #include "services/shell/public/cpp/application_runner.h" | 20 #include "services/shell/public/cpp/application_runner.h" |
| 20 #include "services/shell/public/cpp/connector.h" | 21 #include "services/shell/public/cpp/connector.h" |
| 21 #include "services/shell/public/cpp/shell_client.h" | 22 #include "services/shell/public/cpp/shell_client.h" |
| 22 #include "services/tracing/public/cpp/tracing_impl.h" | 23 #include "services/tracing/public/cpp/tracing_impl.h" |
| 23 #include "ui/aura/mus/mus_util.h" | 24 #include "ui/aura/mus/mus_util.h" |
| 24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/paint_throbber.h" | 26 #include "ui/gfx/paint_throbber.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 navigation::mojom::ViewPtr view, | 124 navigation::mojom::ViewPtr view, |
| 124 navigation::mojom::ViewClientRequest request) | 125 navigation::mojom::ViewClientRequest request) |
| 125 : browser_(browser), | 126 : browser_(browser), |
| 126 type_(type), | 127 type_(type), |
| 127 back_button_(new views::LabelButton(this, base::ASCIIToUTF16("Back"))), | 128 back_button_(new views::LabelButton(this, base::ASCIIToUTF16("Back"))), |
| 128 forward_button_( | 129 forward_button_( |
| 129 new views::LabelButton(this, base::ASCIIToUTF16("Forward"))), | 130 new views::LabelButton(this, base::ASCIIToUTF16("Forward"))), |
| 130 reload_button_( | 131 reload_button_( |
| 131 new views::LabelButton(this, base::ASCIIToUTF16("Reload"))), | 132 new views::LabelButton(this, base::ASCIIToUTF16("Reload"))), |
| 132 prompt_(new views::Textfield), | 133 prompt_(new views::Textfield), |
| 134 debug_button_( | |
| 135 new views::LabelButton(this, base::ASCIIToUTF16("DV"))), | |
| 133 throbber_(new Throbber), | 136 throbber_(new Throbber), |
| 134 progress_bar_(new ProgressBar), | 137 progress_bar_(new ProgressBar), |
| 138 debug_view_(new DebugView), | |
| 135 view_(std::move(view)), | 139 view_(std::move(view)), |
| 136 view_client_binding_(this, std::move(request)) { | 140 view_client_binding_(this, std::move(request)) { |
| 137 set_background(views::Background::CreateStandardPanelBackground()); | 141 set_background(views::Background::CreateStandardPanelBackground()); |
| 138 prompt_->set_controller(this); | 142 prompt_->set_controller(this); |
| 139 back_button_->set_request_focus_on_press(false); | 143 back_button_->set_request_focus_on_press(false); |
| 140 forward_button_->set_request_focus_on_press(false); | 144 forward_button_->set_request_focus_on_press(false); |
| 141 reload_button_->set_request_focus_on_press(false); | 145 reload_button_->set_request_focus_on_press(false); |
| 142 AddChildView(back_button_); | 146 AddChildView(back_button_); |
| 143 AddChildView(forward_button_); | 147 AddChildView(forward_button_); |
| 144 AddChildView(reload_button_); | 148 AddChildView(reload_button_); |
| 145 AddChildView(prompt_); | 149 AddChildView(prompt_); |
| 150 AddChildView(debug_button_); | |
| 146 AddChildView(throbber_); | 151 AddChildView(throbber_); |
| 147 AddChildView(progress_bar_); | 152 AddChildView(progress_bar_); |
| 153 AddChildView(debug_view_); | |
| 154 debug_view_->set_view(view_.get()); | |
| 148 } | 155 } |
| 149 ~UI() override { browser_->RemoveWindow(GetWidget()); } | 156 ~UI() override { browser_->RemoveWindow(GetWidget()); } |
| 150 | 157 |
| 151 void NavigateTo(const GURL& url) { view_->NavigateTo(url); } | 158 void NavigateTo(const GURL& url) { view_->NavigateTo(url); } |
| 152 | 159 |
| 153 private: | 160 private: |
| 154 // Overridden from views::WidgetDelegate: | 161 // Overridden from views::WidgetDelegate: |
| 155 views::View* GetContentsView() override { return this; } | 162 views::View* GetContentsView() override { return this; } |
| 156 base::string16 GetWindowTitle() const override { | 163 base::string16 GetWindowTitle() const override { |
| 157 // TODO(beng): use resources. | 164 // TODO(beng): use resources. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 171 if (sender == back_button_) { | 178 if (sender == back_button_) { |
| 172 view_->GoBack(); | 179 view_->GoBack(); |
| 173 } else if (sender == forward_button_) { | 180 } else if (sender == forward_button_) { |
| 174 view_->GoForward(); | 181 view_->GoForward(); |
| 175 } else if (sender == reload_button_) { | 182 } else if (sender == reload_button_) { |
| 176 if (is_loading_) | 183 if (is_loading_) |
| 177 view_->Stop(); | 184 view_->Stop(); |
| 178 else | 185 else |
| 179 view_->Reload(false); | 186 view_->Reload(false); |
| 180 } | 187 } |
| 188 else if (sender == debug_button_) { | |
|
sky
2016/06/03 22:24:50
nit: else on previous line.
| |
| 189 ToggleDebugView(); | |
| 190 } | |
| 181 } | 191 } |
| 182 | 192 |
| 183 // Overridden from views::View: | 193 // Overridden from views::View: |
| 184 void Layout() override { | 194 void Layout() override { |
| 185 gfx::Rect local_bounds = GetLocalBounds(); | 195 gfx::Rect local_bounds = GetLocalBounds(); |
| 186 gfx::Rect bounds = local_bounds; | 196 gfx::Rect bounds = local_bounds; |
| 187 bounds.Inset(5, 5); | 197 bounds.Inset(5, 5); |
| 188 | 198 |
| 189 gfx::Size ps = back_button_->GetPreferredSize(); | 199 gfx::Size ps = back_button_->GetPreferredSize(); |
| 190 back_button_->SetBoundsRect( | 200 back_button_->SetBoundsRect( |
| 191 gfx::Rect(bounds.x(), bounds.y(), ps.width(), ps.height())); | 201 gfx::Rect(bounds.x(), bounds.y(), ps.width(), ps.height())); |
| 192 ps = forward_button_->GetPreferredSize(); | 202 ps = forward_button_->GetPreferredSize(); |
| 193 forward_button_->SetBoundsRect(gfx::Rect(back_button_->bounds().right() + 5, | 203 forward_button_->SetBoundsRect(gfx::Rect(back_button_->bounds().right() + 5, |
| 194 bounds.y(), ps.width(), | 204 bounds.y(), ps.width(), |
| 195 ps.height())); | 205 ps.height())); |
| 196 ps = reload_button_->GetPreferredSize(); | 206 ps = reload_button_->GetPreferredSize(); |
| 197 reload_button_->SetBoundsRect( | 207 reload_button_->SetBoundsRect( |
| 198 gfx::Rect(forward_button_->bounds().right() + 5, bounds.y(), ps.width(), | 208 gfx::Rect(forward_button_->bounds().right() + 5, bounds.y(), ps.width(), |
| 199 ps.height())); | 209 ps.height())); |
| 200 | 210 |
| 201 ps = prompt_->GetPreferredSize(); | 211 ps = prompt_->GetPreferredSize(); |
| 212 int throbber_size = ps.height(); | |
| 213 gfx::Size debug_ps = debug_button_->GetPreferredSize(); | |
| 202 int prompt_y = | 214 int prompt_y = |
| 203 bounds.y() + (reload_button_->bounds().height() - ps.height()) / 2; | 215 bounds.y() + (reload_button_->bounds().height() - ps.height()) / 2; |
| 204 int width = | 216 int width = |
| 205 bounds.width() - reload_button_->bounds().right() - ps.height() - 10; | 217 bounds.width() - reload_button_->bounds().right() - throbber_size - 15 - |
| 218 debug_ps.width(); | |
| 206 prompt_->SetBoundsRect(gfx::Rect(reload_button_->bounds().right() + 5, | 219 prompt_->SetBoundsRect(gfx::Rect(reload_button_->bounds().right() + 5, |
| 207 prompt_y, width, ps.height())); | 220 prompt_y, width, ps.height())); |
| 208 throbber_->SetBoundsRect(gfx::Rect(prompt_->bounds().right() + 5, | 221 |
| 209 prompt_->bounds().y(), ps.height(), | 222 debug_button_->SetBoundsRect( |
| 210 ps.height())); | 223 gfx::Rect(prompt_->bounds().right() + 5, |
| 224 prompt_->bounds().y(), debug_ps.width(), debug_ps.height())); | |
| 225 | |
| 226 throbber_->SetBoundsRect(gfx::Rect(debug_button_->bounds().right() + 5, | |
| 227 prompt_->bounds().y(), throbber_size, | |
| 228 throbber_size)); | |
| 211 | 229 |
| 212 gfx::Rect progress_bar_rect(local_bounds.x(), | 230 gfx::Rect progress_bar_rect(local_bounds.x(), |
| 213 back_button_->bounds().bottom() + 5, | 231 back_button_->bounds().bottom() + 5, |
| 214 local_bounds.width(), 2); | 232 local_bounds.width(), 2); |
| 215 progress_bar_->SetBoundsRect(progress_bar_rect); | 233 progress_bar_->SetBoundsRect(progress_bar_rect); |
| 216 | 234 |
| 235 int debug_view_height = 0; | |
| 236 if (showing_debug_view_) | |
| 237 debug_view_height = debug_view_->GetPreferredSize().height(); | |
| 238 debug_view_->SetBoundsRect( | |
| 239 gfx::Rect(local_bounds.x(), local_bounds.height() - debug_view_height, | |
| 240 local_bounds.width(), debug_view_height)); | |
| 241 | |
| 217 if (content_area_) { | 242 if (content_area_) { |
| 218 int x = local_bounds.x(); | 243 int x = local_bounds.x(); |
| 219 int y = type_ == Type::POPUP ? 0 : progress_bar_->bounds().bottom(); | 244 int y = type_ == Type::POPUP ? 0 : progress_bar_->bounds().bottom(); |
| 220 gfx::Point offset(x, y); | 245 gfx::Point offset(x, y); |
| 221 ConvertPointToWidget(this, &offset); | 246 ConvertPointToWidget(this, &offset); |
| 222 int width = local_bounds.width(); | 247 int width = local_bounds.width(); |
| 223 int height = local_bounds.height() - y; | 248 int height = local_bounds.height() - y - debug_view_height; |
| 224 content_area_->SetBounds( | 249 content_area_->SetBounds( |
| 225 gfx::Rect(offset.x(), offset.y(), width, height)); | 250 gfx::Rect(offset.x(), offset.y(), width, height)); |
| 226 } | 251 } |
| 227 } | 252 } |
| 228 void ViewHierarchyChanged( | 253 void ViewHierarchyChanged( |
| 229 const views::View::ViewHierarchyChangedDetails& details) override { | 254 const views::View::ViewHierarchyChangedDetails& details) override { |
| 230 if (details.is_add && GetWidget() && !content_area_) { | 255 if (details.is_add && GetWidget() && !content_area_) { |
| 231 mus::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); | 256 mus::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); |
| 232 content_area_ = window->window_tree()->NewWindow(nullptr); | 257 content_area_ = window->window_tree()->NewWindow(nullptr); |
| 233 window->AddChild(content_area_); | 258 window->AddChild(content_area_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 bool user_gesture) override { | 308 bool user_gesture) override { |
| 284 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 309 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 285 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, | 310 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, |
| 286 std::move(view), std::move(request)), | 311 std::move(view), std::move(request)), |
| 287 nullptr, initial_rect); | 312 nullptr, initial_rect); |
| 288 window->Show(); | 313 window->Show(); |
| 289 browser_->AddWindow(window); | 314 browser_->AddWindow(window); |
| 290 } | 315 } |
| 291 void Close() override { GetWidget()->Close(); } | 316 void Close() override { GetWidget()->Close(); } |
| 292 | 317 |
| 318 void ToggleDebugView() { | |
| 319 showing_debug_view_ = !showing_debug_view_; | |
| 320 Layout(); | |
| 321 } | |
| 322 | |
| 293 Browser* browser_; | 323 Browser* browser_; |
| 294 | 324 |
| 295 Type type_; | 325 Type type_; |
| 296 | 326 |
| 297 views::LabelButton* back_button_; | 327 views::LabelButton* back_button_; |
| 298 views::LabelButton* forward_button_; | 328 views::LabelButton* forward_button_; |
| 299 views::LabelButton* reload_button_; | 329 views::LabelButton* reload_button_; |
| 300 views::Textfield* prompt_; | 330 views::Textfield* prompt_; |
| 331 views::LabelButton* debug_button_; | |
| 301 Throbber* throbber_; | 332 Throbber* throbber_; |
| 302 ProgressBar* progress_bar_; | 333 ProgressBar* progress_bar_; |
| 303 | 334 |
| 304 mus::Window* content_area_ = nullptr; | 335 mus::Window* content_area_ = nullptr; |
| 305 | 336 |
| 337 DebugView* debug_view_; | |
| 338 | |
| 306 navigation::mojom::ViewPtr view_; | 339 navigation::mojom::ViewPtr view_; |
| 307 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; | 340 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; |
| 308 | 341 |
| 309 bool is_loading_ = false; | 342 bool is_loading_ = false; |
| 310 base::string16 current_title_; | 343 base::string16 current_title_; |
| 311 | 344 |
| 345 bool showing_debug_view_ = false; | |
| 346 | |
| 312 DISALLOW_COPY_AND_ASSIGN(UI); | 347 DISALLOW_COPY_AND_ASSIGN(UI); |
| 313 }; | 348 }; |
| 314 | 349 |
| 315 Browser::Browser() {} | 350 Browser::Browser() {} |
| 316 Browser::~Browser() {} | 351 Browser::~Browser() {} |
| 317 | 352 |
| 318 void Browser::AddWindow(views::Widget* window) { | 353 void Browser::AddWindow(views::Widget* window) { |
| 319 windows_.push_back(window); | 354 windows_.push_back(window); |
| 320 } | 355 } |
| 321 | 356 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 AddWindow(window); | 401 AddWindow(window); |
| 367 } | 402 } |
| 368 | 403 |
| 369 void Browser::Create(shell::Connection* connection, | 404 void Browser::Create(shell::Connection* connection, |
| 370 mojom::LaunchableRequest request) { | 405 mojom::LaunchableRequest request) { |
| 371 bindings_.AddBinding(this, std::move(request)); | 406 bindings_.AddBinding(this, std::move(request)); |
| 372 } | 407 } |
| 373 | 408 |
| 374 } // namespace browser | 409 } // namespace browser |
| 375 } // namespace mash | 410 } // namespace mash |
| OLD | NEW |