#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
+#include "content/public/common/context_menu_params.h"
#include "content/shell/browser/shell_platform_data_aura.h"
+#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/base/clipboard/clipboard.h"
+#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h"
#include "ui/gfx/screen.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
+#include "ui/views/controls/button/menu_button.h"
+#include "ui/views/controls/button/menu_button_listener.h"
+#include "ui/views/controls/menu/menu_item_view.h"
+#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/controls/webview/webview.h"
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura);
};
+// Model for the "Debug" menu
+class ContextMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
+ public:
+ explicit ContextMenuModel(
+ Shell* shell, const content::ContextMenuParams& params)
+ : ui::SimpleMenuModel(this),
+ shell_(shell),
+ params_(params) {
+ AddItem(COMMAND_OPEN_DEVTOOLS, base::ASCIIToUTF16("Inspect Element"));
+ }
+
+ // ui::SimpleMenuModel::Delegate:
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
+ return false;
+ }
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
+ return true;
+ }
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) OVERRIDE { return false; }
+ virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {
+ switch (command_id) {
+ case COMMAND_OPEN_DEVTOOLS:
+ shell_->ShowDevToolsForElementAt(params_.x, params_.y);
+ break;
+ };
+ }
+
+ private:
+ enum CommandID {
+ COMMAND_OPEN_DEVTOOLS
+ };
+
+ Shell* shell_;
+ content::ContextMenuParams params_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContextMenuModel);
+};
+
// Maintain the UI controls and web view for content shell
class ShellWindowDelegateView : public views::WidgetDelegateView,
public views::TextfieldController,
}
}
+ void ShowWebViewContextMenu(const content::ContextMenuParams& params) {
+ gfx::Point screen_point(params.x, params.y);
+
+ // Convert from content coordinates to window coordinates.
+ // This code copied from chrome_web_contents_view_delegate_views.cc
+ aura::Window* web_contents_window =
+ shell_->web_contents()->GetView()->GetNativeView();
+ aura::Window* root_window = web_contents_window->GetRootWindow();
+ aura::client::ScreenPositionClient* screen_position_client =
+ aura::client::GetScreenPositionClient(root_window);
+ if (screen_position_client) {
+ screen_position_client->ConvertPointToScreen(web_contents_window,
+ &screen_point);
+ }
+
+ context_menu_model_.reset(new ContextMenuModel(shell_, params));
+ context_menu_runner_.reset(
+ new views::MenuRunner(context_menu_model_.get()));
+
+ if (context_menu_runner_->RunMenuAt(web_view_->GetWidget(),
+ NULL, gfx::Rect(screen_point, gfx::Size()),
+ views::MenuItemView::TOPRIGHT, ui::MENU_SOURCE_NONE,
+ views::MenuRunner::CONTEXT_MENU) ==
+ views::MenuRunner::MENU_DELETED)
+ return;
+ }
+
+ void OnWebContentsFocused(content::WebContents* web_contents) {
+ if (web_view_->GetWebContents() == web_contents)
+ web_view_->OnWebContentsFocused(web_contents);
+ }
+
private:
// Initialize the UI control contained in shell window
void InitShellWindow() {
toolbar_column_set->AddColumn(views::GridLayout::FILL,
views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
+ toolbar_column_set->AddPaddingColumn(0, 2);
// Fill up the first row
toolbar_layout->StartRow(0, 0);
views::LabelButton* refresh_button_;
views::LabelButton* stop_button_;
views::Textfield* url_entry_;
+ scoped_ptr<ContextMenuModel> context_menu_model_;
+ scoped_ptr<views::MenuRunner> context_menu_runner_;
// Contents view contains the web contents view
View* contents_view_;
wm_test_helper_->GetDefaultParent(NULL, NULL, gfx::Rect()),
gfx::Rect(0, 0, width, height));
#else
- window_widget_ = views::Widget::CreateWindowWithBounds(
- new ShellWindowDelegateView(this), gfx::Rect(0, 0, width, height));
+ window_widget_ = new views::Widget;
+ views::Widget::InitParams params;
+ params.bounds = gfx::Rect(0, 0, width, height);
+ params.delegate = new ShellWindowDelegateView(this);
+ params.top_level = true;
+ params.remove_standard_frame = true;
+ window_widget_->Init(params);
#endif
content_size_ = gfx::Size(width, height);
window_widget_->UpdateWindowTitle();
}
+bool Shell::PlatformHandleContextMenu(
+ const content::ContextMenuParams& params) {
+ if (headless_)
+ return true;
+ ShellWindowDelegateView* delegate_view =
+ static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate());
+ delegate_view->ShowWebViewContextMenu(params);
+ return true;
+}
+
+void Shell::PlatformWebContentsFocused(WebContents* contents) {
+ if (headless_)
+ return;
+ ShellWindowDelegateView* delegate_view =
+ static_cast<ShellWindowDelegateView*>(window_widget_->widget_delegate());
+ delegate_view->OnWebContentsFocused(contents);
+}
+
} // namespace content