Commit cac4680a authored by oshima@chromium.org's avatar oshima@chromium.org

Add minimum Context Menu.

More menus will be added in separate CL.

BUG=380438
TEST=None
R=mukai@chromium.org,ben@chromium.org

Review URL: https://codereview.chromium.org/448063005

Cr-Commit-Position: refs/heads/master@{#288346}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288346 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d56c9d0
......@@ -84,6 +84,8 @@
'dependencies': [
'athena_lib',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../components/components.gyp:renderer_context_menu',
'../components/components.gyp:web_modal',
'../content/content.gyp:content_browser',
'../ui/app_list/app_list.gyp:app_list',
'../ui/keyboard/keyboard.gyp:keyboard',
......@@ -98,12 +100,16 @@
'sources': [
'content/public/content_activity_factory.h',
'content/public/content_app_model_builder.h',
'content/public/web_contents_view_delegate_creator.h',
'content/content_activity_factory.cc',
'content/content_app_model_builder.cc',
'content/app_activity.h',
'content/app_activity.cc',
'content/render_view_context_menu_impl.cc',
'content/render_view_context_menu_impl.h',
'content/web_activity.h',
'content/web_activity.cc',
'content/web_contents_view_delegate_factory_impl.cc',
'virtual_keyboard/public/virtual_keyboard_manager.h',
'virtual_keyboard/virtual_keyboard_manager_impl.cc',
],
......
......@@ -2,11 +2,14 @@ include_rules = [
"+athena/activity/public",
"+athena/home/public",
"+athena/input/public",
"+components/renderer_context_menu",
"+components/web_modal",
"+content/public",
"+extensions/browser",
"+extensions/common",
"+extensions/shell/browser",
"+ui/app_list",
"+ui/aura",
"+ui/gfx",
"+ui/views",
]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_CONTENT_PUBLIC_WEB_CONTENTS_VIEW_DELEGATE_FACTORY_H_
#define ATHENA_CONTENT_PUBLIC_WEB_CONTENTS_VIEW_DELEGATE_FACTORY_H_
#include "athena/athena_export.h"
namespace content {
class WebContents;
class WebContentsViewDelegate;
}
namespace athena {
ATHENA_EXPORT content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
content::WebContents* web_contents);
} // namespace athena
#endif // ATHENA_CONTENT_PUBLIC_WEB_CONTENTS_VIEW_DELEGATE_FACTORY_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/content/render_view_context_menu_impl.h"
#include "base/strings/utf_string_conversions.h"
#include "components/renderer_context_menu/context_menu_content_type.h"
#include "components/renderer_context_menu/views/toolkit_delegate_views.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
namespace athena {
namespace {
enum {
CMD_BACK,
CMD_FORWARD,
CMD_RELOAD,
CMD_VIEW_SOURCE,
CMD_LAST,
};
// Max number of custom command ids allowd.
const int kNumCustomCommandIds = 1000;
void AppendPageItems(ui::SimpleMenuModel* menu_model) {
menu_model->AddItem(CMD_BACK, base::ASCIIToUTF16("Back"));
menu_model->AddItem(CMD_FORWARD, base::ASCIIToUTF16("Forward"));
menu_model->AddItem(CMD_RELOAD, base::ASCIIToUTF16("Reload"));
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
menu_model->AddItem(CMD_VIEW_SOURCE, base::ASCIIToUTF16("View Source"));
}
} // namespace
RenderViewContextMenuImpl::RenderViewContextMenuImpl(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params)
: RenderViewContextMenuBase(render_frame_host, params) {
SetContentCustomCommandIdRange(CMD_LAST, CMD_LAST + kNumCustomCommandIds);
// TODO(oshima): Support other types
set_content_type(
new ContextMenuContentType(source_web_contents_, params, true));
set_toolkit_delegate(scoped_ptr<ToolkitDelegate>(new ToolkitDelegateViews));
}
RenderViewContextMenuImpl::~RenderViewContextMenuImpl() {
}
void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent,
const gfx::Point& point,
ui::MenuSourceType type) {
static_cast<ToolkitDelegateViews*>(toolkit_delegate())
->RunMenuAt(parent, point, type);
}
void RenderViewContextMenuImpl::InitMenu() {
RenderViewContextMenuBase::InitMenu();
if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) {
AppendPageItems(&menu_model_);
}
}
void RenderViewContextMenuImpl::RecordShownItem(int id) {
// TODO(oshima): Imelement UMA stats. crbug.com/401673
NOTIMPLEMENTED();
}
void RenderViewContextMenuImpl::RecordUsedItem(int id) {
// TODO(oshima): Imelement UMA stats. crbug.com/401673
NOTIMPLEMENTED();
}
#if defined(ENABLE_PLUGINS)
void RenderViewContextMenuImpl::HandleAuthorizeAllPlugins() {
}
#endif
void RenderViewContextMenuImpl::NotifyMenuShown() {
}
void RenderViewContextMenuImpl::NotifyURLOpened(
const GURL& url,
content::WebContents* new_contents) {
}
bool RenderViewContextMenuImpl::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
NOTIMPLEMENTED();
return false;
}
bool RenderViewContextMenuImpl::IsCommandIdChecked(int command_id) const {
return false;
}
bool RenderViewContextMenuImpl::IsCommandIdEnabled(int command_id) const {
if (RenderViewContextMenuBase::IsCommandIdEnabled(command_id))
return true;
switch (command_id) {
case CMD_BACK:
return source_web_contents_->GetController().CanGoBack();
case CMD_FORWARD:
return source_web_contents_->GetController().CanGoForward();
case CMD_RELOAD:
return true;
case CMD_VIEW_SOURCE:
return source_web_contents_->GetController().CanViewSource();
}
return false;
}
void RenderViewContextMenuImpl::ExecuteCommand(int command_id,
int event_flags) {
RenderViewContextMenuBase::ExecuteCommand(command_id, event_flags);
if (command_executed_)
return;
command_executed_ = true;
switch (command_id) {
case CMD_BACK:
source_web_contents_->GetController().GoBack();
break;
case CMD_FORWARD:
source_web_contents_->GetController().GoForward();
break;
case CMD_RELOAD:
source_web_contents_->GetController().Reload(true);
break;
case CMD_VIEW_SOURCE:
source_web_contents_->ViewSource();
break;
}
}
} // namespace athena
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_CONTENT_RENDER_VIEW_CONTEXT_MENU_IMPL_H_
#define ATHENA_CONTENT_RENDER_VIEW_CONTEXT_MENU_IMPL_H_
#include "components/renderer_context_menu/render_view_context_menu_base.h"
namespace views {
class Widget;
}
namespace gfx {
class Point;
}
namespace athena {
class RenderViewContextMenuImpl : public RenderViewContextMenuBase {
public:
RenderViewContextMenuImpl(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params);
virtual ~RenderViewContextMenuImpl();
void RunMenuAt(views::Widget* parent,
const gfx::Point& point,
ui::MenuSourceType type);
private:
// RenderViewContextMenuBase:
virtual void InitMenu() OVERRIDE;
virtual void RecordShownItem(int id) OVERRIDE;
virtual void RecordUsedItem(int id) OVERRIDE;
#if defined(ENABLE_PLUGINS)
virtual void HandleAuthorizeAllPlugins() OVERRIDE;
#endif
virtual void NotifyMenuShown() OVERRIDE;
virtual void NotifyURLOpened(const GURL& url,
content::WebContents* new_contents) OVERRIDE;
// ui::SimpleMenuModel:
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuImpl);
};
} // namespace athena
#endif // ATHENA_CONTENT_RENDER_VIEW_CONTEXT_MENU_IMPL_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/content/public/web_contents_view_delegate_creator.h"
#include "athena/content/render_view_context_menu_impl.h"
#include "components/web_modal/popup_manager.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
namespace athena {
namespace {
class WebContentsViewDelegateImpl : public content::WebContentsViewDelegate {
public:
explicit WebContentsViewDelegateImpl(content::WebContents* web_contents)
: web_contents_(web_contents) {}
virtual ~WebContentsViewDelegateImpl() {}
virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE {
// TODO(oshima): crbug.com/401610
return NULL;
}
virtual bool Focus() OVERRIDE {
web_modal::PopupManager* popup_manager =
web_modal::PopupManager::FromWebContents(web_contents_);
if (popup_manager)
popup_manager->WasFocused(web_contents_);
return false;
}
virtual void TakeFocus(bool reverse) OVERRIDE {}
virtual void StoreFocus() OVERRIDE {}
virtual void RestoreFocus() OVERRIDE {}
virtual void ShowContextMenu(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) OVERRIDE {
ShowMenu(BuildMenu(
content::WebContents::FromRenderFrameHost(render_frame_host), params));
}
virtual void SizeChanged(const gfx::Size& size) OVERRIDE {
// TODO(oshima|sadrul): Implement this when sad_tab is componentized.
// See c/b/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc
}
scoped_ptr<RenderViewContextMenuImpl> BuildMenu(
content::WebContents* web_contents,
const content::ContextMenuParams& params) {
scoped_ptr<RenderViewContextMenuImpl> menu;
content::RenderFrameHost* focused_frame = web_contents->GetFocusedFrame();
// If the frame tree does not have a focused frame at this point, do not
// bother creating RenderViewContextMenuViews.
// This happens if the frame has navigated to a different page before
// ContextMenu message was received by the current RenderFrameHost.
if (focused_frame) {
menu.reset(new RenderViewContextMenuImpl(focused_frame, params));
menu->Init();
}
return menu.Pass();
}
void ShowMenu(scoped_ptr<RenderViewContextMenuImpl> menu) {
context_menu_.reset(menu.release());
if (!context_menu_.get())
return;
// Menus need a Widget to work. If we're not the active tab we won't
// necessarily be in a widget.
views::Widget* top_level_widget = GetTopLevelWidget();
if (!top_level_widget)
return;
const content::ContextMenuParams& params = context_menu_->params();
// Don't show empty menus.
if (context_menu_->menu_model().GetItemCount() == 0)
return;
gfx::Point screen_point(params.x, params.y);
// Convert from target window coordinates to root window coordinates.
aura::Window* target_window = GetActiveNativeView();
aura::Window* root_window = target_window->GetRootWindow();
aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(root_window);
if (screen_position_client) {
screen_position_client->ConvertPointToScreen(target_window,
&screen_point);
}
// Enable recursive tasks on the message loop so we can get updates while
// the context menu is being displayed.
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
context_menu_->RunMenuAt(
top_level_widget, screen_point, params.source_type);
}
aura::Window* GetActiveNativeView() {
return web_contents_->GetFullscreenRenderWidgetHostView()
? web_contents_->GetFullscreenRenderWidgetHostView()
->GetNativeView()
: web_contents_->GetNativeView();
}
views::Widget* GetTopLevelWidget() {
return views::Widget::GetTopLevelWidgetForNativeView(GetActiveNativeView());
}
views::FocusManager* GetFocusManager() {
views::Widget* toplevel_widget = GetTopLevelWidget();
return toplevel_widget ? toplevel_widget->GetFocusManager() : NULL;
}
void SetInitialFocus() {
if (web_contents_->FocusLocationBarByDefault()) {
if (web_contents_->GetDelegate())
web_contents_->GetDelegate()->SetFocusToLocationBar(false);
} else {
web_contents_->Focus();
}
}
scoped_ptr<RenderViewContextMenuImpl> context_menu_;
content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(WebContentsViewDelegateImpl);
};
} // namespace
content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
content::WebContents* web_contents) {
return new WebContentsViewDelegateImpl(web_contents);
}
} // namespace athena
namespace web_modal {
SingleWebContentsDialogManager*
WebContentsModalDialogManager::CreateNativeWebModalManager(
NativeWebContentsModalDialog dialog,
SingleWebContentsDialogManagerDelegate* native_delegate) {
// TODO(oshima): Investigate if we need to implement this.
NOTREACHED();
return NULL;
}
} // namespace web_modal
......@@ -4,6 +4,7 @@
#include "athena/content/public/content_activity_factory.h"
#include "athena/content/public/content_app_model_builder.h"
#include "athena/content/public/web_contents_view_delegate_creator.h"
#include "athena/home/public/home_card.h"
#include "athena/main/athena_app_window_controller.h"
#include "athena/main/athena_launcher.h"
......@@ -145,8 +146,7 @@ class AthenaContentBrowserClient
// content::ContentBrowserClient:
virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate(
content::WebContents* web_contents) OVERRIDE {
// TODO(oshima): Implement athena's WebContentsViewDelegate.
return NULL;
return athena::CreateWebContentsViewDelegate(web_contents);
}
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment