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 12 matching lines...) Expand all Loading... |
170 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 177 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
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); |
| 187 } else if (sender == debug_button_) { |
| 188 ToggleDebugView(); |
180 } | 189 } |
181 } | 190 } |
182 | 191 |
183 // Overridden from views::View: | 192 // Overridden from views::View: |
184 void Layout() override { | 193 void Layout() override { |
185 gfx::Rect local_bounds = GetLocalBounds(); | 194 gfx::Rect local_bounds = GetLocalBounds(); |
186 gfx::Rect bounds = local_bounds; | 195 gfx::Rect bounds = local_bounds; |
187 bounds.Inset(5, 5); | 196 bounds.Inset(5, 5); |
188 | 197 |
189 gfx::Size ps = back_button_->GetPreferredSize(); | 198 gfx::Size ps = back_button_->GetPreferredSize(); |
190 back_button_->SetBoundsRect( | 199 back_button_->SetBoundsRect( |
191 gfx::Rect(bounds.x(), bounds.y(), ps.width(), ps.height())); | 200 gfx::Rect(bounds.x(), bounds.y(), ps.width(), ps.height())); |
192 ps = forward_button_->GetPreferredSize(); | 201 ps = forward_button_->GetPreferredSize(); |
193 forward_button_->SetBoundsRect(gfx::Rect(back_button_->bounds().right() + 5, | 202 forward_button_->SetBoundsRect(gfx::Rect(back_button_->bounds().right() + 5, |
194 bounds.y(), ps.width(), | 203 bounds.y(), ps.width(), |
195 ps.height())); | 204 ps.height())); |
196 ps = reload_button_->GetPreferredSize(); | 205 ps = reload_button_->GetPreferredSize(); |
197 reload_button_->SetBoundsRect( | 206 reload_button_->SetBoundsRect( |
198 gfx::Rect(forward_button_->bounds().right() + 5, bounds.y(), ps.width(), | 207 gfx::Rect(forward_button_->bounds().right() + 5, bounds.y(), ps.width(), |
199 ps.height())); | 208 ps.height())); |
200 | 209 |
201 ps = prompt_->GetPreferredSize(); | 210 ps = prompt_->GetPreferredSize(); |
| 211 int throbber_size = ps.height(); |
| 212 gfx::Size debug_ps = debug_button_->GetPreferredSize(); |
202 int prompt_y = | 213 int prompt_y = |
203 bounds.y() + (reload_button_->bounds().height() - ps.height()) / 2; | 214 bounds.y() + (reload_button_->bounds().height() - ps.height()) / 2; |
204 int width = | 215 int width = |
205 bounds.width() - reload_button_->bounds().right() - ps.height() - 10; | 216 bounds.width() - reload_button_->bounds().right() - throbber_size - 15 - |
| 217 debug_ps.width(); |
206 prompt_->SetBoundsRect(gfx::Rect(reload_button_->bounds().right() + 5, | 218 prompt_->SetBoundsRect(gfx::Rect(reload_button_->bounds().right() + 5, |
207 prompt_y, width, ps.height())); | 219 prompt_y, width, ps.height())); |
208 throbber_->SetBoundsRect(gfx::Rect(prompt_->bounds().right() + 5, | 220 |
209 prompt_->bounds().y(), ps.height(), | 221 debug_button_->SetBoundsRect( |
210 ps.height())); | 222 gfx::Rect(prompt_->bounds().right() + 5, |
| 223 prompt_->bounds().y(), debug_ps.width(), debug_ps.height())); |
| 224 |
| 225 throbber_->SetBoundsRect(gfx::Rect(debug_button_->bounds().right() + 5, |
| 226 prompt_->bounds().y(), throbber_size, |
| 227 throbber_size)); |
211 | 228 |
212 gfx::Rect progress_bar_rect(local_bounds.x(), | 229 gfx::Rect progress_bar_rect(local_bounds.x(), |
213 back_button_->bounds().bottom() + 5, | 230 back_button_->bounds().bottom() + 5, |
214 local_bounds.width(), 2); | 231 local_bounds.width(), 2); |
215 progress_bar_->SetBoundsRect(progress_bar_rect); | 232 progress_bar_->SetBoundsRect(progress_bar_rect); |
216 | 233 |
| 234 int debug_view_height = 0; |
| 235 if (showing_debug_view_) |
| 236 debug_view_height = debug_view_->GetPreferredSize().height(); |
| 237 debug_view_->SetBoundsRect( |
| 238 gfx::Rect(local_bounds.x(), local_bounds.height() - debug_view_height, |
| 239 local_bounds.width(), debug_view_height)); |
| 240 |
217 if (content_area_) { | 241 if (content_area_) { |
218 int x = local_bounds.x(); | 242 int x = local_bounds.x(); |
219 int y = type_ == Type::POPUP ? 0 : progress_bar_->bounds().bottom(); | 243 int y = type_ == Type::POPUP ? 0 : progress_bar_->bounds().bottom(); |
220 gfx::Point offset(x, y); | 244 gfx::Point offset(x, y); |
221 ConvertPointToWidget(this, &offset); | 245 ConvertPointToWidget(this, &offset); |
222 int width = local_bounds.width(); | 246 int width = local_bounds.width(); |
223 int height = local_bounds.height() - y; | 247 int height = local_bounds.height() - y - debug_view_height; |
224 content_area_->SetBounds( | 248 content_area_->SetBounds( |
225 gfx::Rect(offset.x(), offset.y(), width, height)); | 249 gfx::Rect(offset.x(), offset.y(), width, height)); |
226 } | 250 } |
227 } | 251 } |
228 void ViewHierarchyChanged( | 252 void ViewHierarchyChanged( |
229 const views::View::ViewHierarchyChangedDetails& details) override { | 253 const views::View::ViewHierarchyChangedDetails& details) override { |
230 if (details.is_add && GetWidget() && !content_area_) { | 254 if (details.is_add && GetWidget() && !content_area_) { |
231 mus::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); | 255 mus::Window* window = aura::GetMusWindow(GetWidget()->GetNativeWindow()); |
232 content_area_ = window->window_tree()->NewWindow(nullptr); | 256 content_area_ = window->window_tree()->NewWindow(nullptr); |
233 window->AddChild(content_area_); | 257 window->AddChild(content_area_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 bool user_gesture) override { | 307 bool user_gesture) override { |
284 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 308 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
285 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, | 309 new UI(browser_, is_popup ? UI::Type::POPUP : UI::Type::WINDOW, |
286 std::move(view), std::move(request)), | 310 std::move(view), std::move(request)), |
287 nullptr, initial_rect); | 311 nullptr, initial_rect); |
288 window->Show(); | 312 window->Show(); |
289 browser_->AddWindow(window); | 313 browser_->AddWindow(window); |
290 } | 314 } |
291 void Close() override { GetWidget()->Close(); } | 315 void Close() override { GetWidget()->Close(); } |
292 | 316 |
| 317 void ToggleDebugView() { |
| 318 showing_debug_view_ = !showing_debug_view_; |
| 319 Layout(); |
| 320 } |
| 321 |
293 Browser* browser_; | 322 Browser* browser_; |
294 | 323 |
295 Type type_; | 324 Type type_; |
296 | 325 |
297 views::LabelButton* back_button_; | 326 views::LabelButton* back_button_; |
298 views::LabelButton* forward_button_; | 327 views::LabelButton* forward_button_; |
299 views::LabelButton* reload_button_; | 328 views::LabelButton* reload_button_; |
300 views::Textfield* prompt_; | 329 views::Textfield* prompt_; |
| 330 views::LabelButton* debug_button_; |
301 Throbber* throbber_; | 331 Throbber* throbber_; |
302 ProgressBar* progress_bar_; | 332 ProgressBar* progress_bar_; |
303 | 333 |
304 mus::Window* content_area_ = nullptr; | 334 mus::Window* content_area_ = nullptr; |
305 | 335 |
| 336 DebugView* debug_view_; |
| 337 |
306 navigation::mojom::ViewPtr view_; | 338 navigation::mojom::ViewPtr view_; |
307 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; | 339 mojo::Binding<navigation::mojom::ViewClient> view_client_binding_; |
308 | 340 |
309 bool is_loading_ = false; | 341 bool is_loading_ = false; |
310 base::string16 current_title_; | 342 base::string16 current_title_; |
311 | 343 |
| 344 bool showing_debug_view_ = false; |
| 345 |
312 DISALLOW_COPY_AND_ASSIGN(UI); | 346 DISALLOW_COPY_AND_ASSIGN(UI); |
313 }; | 347 }; |
314 | 348 |
315 Browser::Browser() {} | 349 Browser::Browser() {} |
316 Browser::~Browser() {} | 350 Browser::~Browser() {} |
317 | 351 |
318 void Browser::AddWindow(views::Widget* window) { | 352 void Browser::AddWindow(views::Widget* window) { |
319 windows_.push_back(window); | 353 windows_.push_back(window); |
320 } | 354 } |
321 | 355 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 AddWindow(window); | 400 AddWindow(window); |
367 } | 401 } |
368 | 402 |
369 void Browser::Create(shell::Connection* connection, | 403 void Browser::Create(shell::Connection* connection, |
370 mojom::LaunchableRequest request) { | 404 mojom::LaunchableRequest request) { |
371 bindings_.AddBinding(this, std::move(request)); | 405 bindings_.AddBinding(this, std::move(request)); |
372 } | 406 } |
373 | 407 |
374 } // namespace browser | 408 } // namespace browser |
375 } // namespace mash | 409 } // namespace mash |
OLD | NEW |