| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell.h" | 5 #include "content/shell/browser/shell.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/public/browser/context_factory.h" | 13 #include "content/public/browser/context_factory.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/context_menu_params.h" | |
| 17 #include "content/shell/browser/shell_platform_data_aura.h" | 16 #include "content/shell/browser/shell_platform_data_aura.h" |
| 18 #include "ui/aura/client/screen_position_client.h" | |
| 19 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| 20 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 22 #include "ui/base/clipboard/clipboard.h" | 20 #include "ui/base/clipboard/clipboard.h" |
| 23 #include "ui/base/models/simple_menu_model.h" | |
| 24 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" |
| 26 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
| 27 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| 28 #include "ui/views/controls/button/label_button.h" | 25 #include "ui/views/controls/button/label_button.h" |
| 29 #include "ui/views/controls/button/menu_button.h" | |
| 30 #include "ui/views/controls/button/menu_button_listener.h" | |
| 31 #include "ui/views/controls/menu/menu_runner.h" | |
| 32 #include "ui/views/controls/textfield/textfield.h" | 26 #include "ui/views/controls/textfield/textfield.h" |
| 33 #include "ui/views/controls/textfield/textfield_controller.h" | 27 #include "ui/views/controls/textfield/textfield_controller.h" |
| 34 #include "ui/views/controls/webview/webview.h" | 28 #include "ui/views/controls/webview/webview.h" |
| 35 #include "ui/views/layout/fill_layout.h" | 29 #include "ui/views/layout/fill_layout.h" |
| 36 #include "ui/views/layout/grid_layout.h" | 30 #include "ui/views/layout/grid_layout.h" |
| 37 #include "ui/views/test/desktop_test_views_delegate.h" | 31 #include "ui/views/test/desktop_test_views_delegate.h" |
| 38 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
| 39 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 40 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
| 41 | 35 |
| 42 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 43 #include "ui/aura/test/test_screen.h" | 37 #include "ui/aura/test/test_screen.h" |
| 44 #include "ui/wm/test/wm_test_helper.h" | 38 #include "ui/wm/test/wm_test_helper.h" |
| 45 #else // !defined(OS_CHROMEOS) | 39 #else // !defined(OS_CHROMEOS) |
| 46 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 40 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 47 #endif | 41 #endif |
| 48 | 42 |
| 49 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 50 #include <fcntl.h> | 44 #include <fcntl.h> |
| 51 #include <io.h> | 45 #include <io.h> |
| 52 #endif | 46 #endif |
| 53 | 47 |
| 54 namespace content { | 48 namespace content { |
| 55 | 49 |
| 56 namespace { | 50 namespace { |
| 57 | 51 |
| 58 // Model for the "Debug" menu | |
| 59 class ContextMenuModel : public ui::SimpleMenuModel, | |
| 60 public ui::SimpleMenuModel::Delegate { | |
| 61 public: | |
| 62 explicit ContextMenuModel( | |
| 63 Shell* shell, const content::ContextMenuParams& params) | |
| 64 : ui::SimpleMenuModel(this), | |
| 65 shell_(shell), | |
| 66 params_(params) { | |
| 67 AddItem(COMMAND_OPEN_DEVTOOLS, base::ASCIIToUTF16("Inspect Element")); | |
| 68 } | |
| 69 | |
| 70 // ui::SimpleMenuModel::Delegate: | |
| 71 bool IsCommandIdChecked(int command_id) const override { return false; } | |
| 72 bool IsCommandIdEnabled(int command_id) const override { return true; } | |
| 73 bool GetAcceleratorForCommandId(int command_id, | |
| 74 ui::Accelerator* accelerator) const override { | |
| 75 return false; | |
| 76 } | |
| 77 void ExecuteCommand(int command_id, int event_flags) override { | |
| 78 switch (command_id) { | |
| 79 case COMMAND_OPEN_DEVTOOLS: | |
| 80 shell_->ShowDevToolsForElementAt(params_.x, params_.y); | |
| 81 break; | |
| 82 }; | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 enum CommandID { | |
| 87 COMMAND_OPEN_DEVTOOLS | |
| 88 }; | |
| 89 | |
| 90 Shell* shell_; | |
| 91 content::ContextMenuParams params_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(ContextMenuModel); | |
| 94 }; | |
| 95 | |
| 96 // Maintain the UI controls and web view for content shell | 52 // Maintain the UI controls and web view for content shell |
| 97 class ShellWindowDelegateView : public views::WidgetDelegateView, | 53 class ShellWindowDelegateView : public views::WidgetDelegateView, |
| 98 public views::TextfieldController, | 54 public views::TextfieldController, |
| 99 public views::ButtonListener { | 55 public views::ButtonListener { |
| 100 public: | 56 public: |
| 101 enum UIControl { | 57 enum UIControl { |
| 102 BACK_BUTTON, | 58 BACK_BUTTON, |
| 103 FORWARD_BUTTON, | 59 FORWARD_BUTTON, |
| 104 STOP_BUTTON | 60 STOP_BUTTON |
| 105 }; | 61 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 : views::CustomButton::STATE_DISABLED); | 99 : views::CustomButton::STATE_DISABLED); |
| 144 } else if (control == FORWARD_BUTTON) { | 100 } else if (control == FORWARD_BUTTON) { |
| 145 forward_button_->SetState(is_enabled ? views::CustomButton::STATE_NORMAL | 101 forward_button_->SetState(is_enabled ? views::CustomButton::STATE_NORMAL |
| 146 : views::CustomButton::STATE_DISABLED); | 102 : views::CustomButton::STATE_DISABLED); |
| 147 } else if (control == STOP_BUTTON) { | 103 } else if (control == STOP_BUTTON) { |
| 148 stop_button_->SetState(is_enabled ? views::CustomButton::STATE_NORMAL | 104 stop_button_->SetState(is_enabled ? views::CustomButton::STATE_NORMAL |
| 149 : views::CustomButton::STATE_DISABLED); | 105 : views::CustomButton::STATE_DISABLED); |
| 150 } | 106 } |
| 151 } | 107 } |
| 152 | 108 |
| 153 void ShowWebViewContextMenu(const content::ContextMenuParams& params) { | |
| 154 gfx::Point screen_point(params.x, params.y); | |
| 155 | |
| 156 // Convert from content coordinates to window coordinates. | |
| 157 // This code copied from chrome_web_contents_view_delegate_views.cc | |
| 158 aura::Window* web_contents_window = | |
| 159 shell_->web_contents()->GetNativeView(); | |
| 160 aura::Window* root_window = web_contents_window->GetRootWindow(); | |
| 161 aura::client::ScreenPositionClient* screen_position_client = | |
| 162 aura::client::GetScreenPositionClient(root_window); | |
| 163 if (screen_position_client) { | |
| 164 screen_position_client->ConvertPointToScreen(web_contents_window, | |
| 165 &screen_point); | |
| 166 } | |
| 167 | |
| 168 context_menu_model_.reset(new ContextMenuModel(shell_, params)); | |
| 169 context_menu_runner_.reset(new views::MenuRunner( | |
| 170 context_menu_model_.get(), views::MenuRunner::CONTEXT_MENU)); | |
| 171 | |
| 172 if (context_menu_runner_->RunMenuAt(web_view_->GetWidget(), | |
| 173 NULL, | |
| 174 gfx::Rect(screen_point, gfx::Size()), | |
| 175 views::MENU_ANCHOR_TOPRIGHT, | |
| 176 ui::MENU_SOURCE_NONE) == | |
| 177 views::MenuRunner::MENU_DELETED) { | |
| 178 return; | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 private: | 109 private: |
| 183 // Initialize the UI control contained in shell window | 110 // Initialize the UI control contained in shell window |
| 184 void InitShellWindow() { | 111 void InitShellWindow() { |
| 185 set_background(views::Background::CreateStandardPanelBackground()); | 112 set_background(views::Background::CreateStandardPanelBackground()); |
| 186 | 113 |
| 187 views::GridLayout* layout = new views::GridLayout(this); | 114 views::GridLayout* layout = new views::GridLayout(this); |
| 188 SetLayoutManager(layout); | 115 SetLayoutManager(layout); |
| 189 | 116 |
| 190 views::ColumnSet* column_set = layout->AddColumnSet(0); | 117 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 191 column_set->AddPaddingColumn(0, 2); | 118 column_set->AddPaddingColumn(0, 2); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Window title | 292 // Window title |
| 366 base::string16 title_; | 293 base::string16 title_; |
| 367 | 294 |
| 368 // Toolbar view contains forward/backward/reload button and URL entry | 295 // Toolbar view contains forward/backward/reload button and URL entry |
| 369 View* toolbar_view_; | 296 View* toolbar_view_; |
| 370 views::LabelButton* back_button_; | 297 views::LabelButton* back_button_; |
| 371 views::LabelButton* forward_button_; | 298 views::LabelButton* forward_button_; |
| 372 views::LabelButton* refresh_button_; | 299 views::LabelButton* refresh_button_; |
| 373 views::LabelButton* stop_button_; | 300 views::LabelButton* stop_button_; |
| 374 views::Textfield* url_entry_; | 301 views::Textfield* url_entry_; |
| 375 std::unique_ptr<ContextMenuModel> context_menu_model_; | |
| 376 std::unique_ptr<views::MenuRunner> context_menu_runner_; | |
| 377 | 302 |
| 378 // Contents view contains the web contents view | 303 // Contents view contains the web contents view |
| 379 View* contents_view_; | 304 View* contents_view_; |
| 380 views::WebView* web_view_; | 305 views::WebView* web_view_; |
| 381 | 306 |
| 382 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); | 307 DISALLOW_COPY_AND_ASSIGN(ShellWindowDelegateView); |
| 383 }; | 308 }; |
| 384 | 309 |
| 385 } // namespace | 310 } // namespace |
| 386 | 311 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 443 |
| 519 void Shell::PlatformSetTitle(const base::string16& title) { | 444 void Shell::PlatformSetTitle(const base::string16& title) { |
| 520 if (headless_) | 445 if (headless_) |
| 521 return; | 446 return; |
| 522 ShellWindowDelegateView* delegate_view = | 447 ShellWindowDelegateView* delegate_view = |
| 523 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | 448 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); |
| 524 delegate_view->SetWindowTitle(title); | 449 delegate_view->SetWindowTitle(title); |
| 525 window_widget_->UpdateWindowTitle(); | 450 window_widget_->UpdateWindowTitle(); |
| 526 } | 451 } |
| 527 | 452 |
| 528 bool Shell::PlatformHandleContextMenu( | |
| 529 const content::ContextMenuParams& params) { | |
| 530 if (headless_) | |
| 531 return true; | |
| 532 ShellWindowDelegateView* delegate_view = | |
| 533 static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate()); | |
| 534 delegate_view->ShowWebViewContextMenu(params); | |
| 535 return true; | |
| 536 } | |
| 537 | |
| 538 } // namespace content | 453 } // namespace content |
| OLD | NEW |