Commit 8490591e authored by mgiuca's avatar mgiuca Committed by Commit bot

Added "Exit full screen" to context menu.

This item is only shown when in fullscreen, and allows users to exit
fullscreen using the mouse (for users who don't have a keyboard
attached).

This is still not foolproof (as it won't work on a site that captures
the right-click menu) but should work in the majority of cases.

BUG=594868
TEST=https://permission.site. Click Fullscreen. Right-click background; should
     see "Exit full screen ... Esc".
TEST=F11 to go fullscreen. Right-click background; should see
     "Exit full screen ... F11".

Review-Url: https://codereview.chromium.org/2116973002
Cr-Commit-Position: refs/heads/master@{#404589}
parent c1e6c531
...@@ -325,6 +325,7 @@ ...@@ -325,6 +325,7 @@
#define IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP 50163 #define IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP 50163
#define IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD 50165 #define IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD 50165
#define IDC_CONTENT_CONTEXT_GENERATEPASSWORD 50166 #define IDC_CONTENT_CONTEXT_GENERATEPASSWORD 50166
#define IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN 50167
// Frame items. // Frame items.
#define IDC_CONTENT_CONTEXT_RELOADFRAME 50170 #define IDC_CONTENT_CONTEXT_RELOADFRAME 50170
#define IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE 50171 #define IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE 50171
......
...@@ -553,6 +553,9 @@ are declared in build/common.gypi. ...@@ -553,6 +553,9 @@ are declared in build/common.gypi.
<message name="IDS_CONTENT_CONTEXT_TRANSLATE" desc="The name of the Translate command in the content area context menu"> <message name="IDS_CONTENT_CONTEXT_TRANSLATE" desc="The name of the Translate command in the content area context menu">
&amp;Translate to <ph name="LANGUAGE">$1<ex>English</ex></ph> &amp;Translate to <ph name="LANGUAGE">$1<ex>English</ex></ph>
</message> </message>
<message name="IDS_CONTENT_CONTEXT_EXIT_FULLSCREEN" desc="The name of the Exit Full Screen command in the content area context menu">
Exit full screen
</message>
<message name="IDS_CONTENT_CONTEXT_RELOADFRAME" desc="The name of the Reload Frame command in the content area context menu"> <message name="IDS_CONTENT_CONTEXT_RELOADFRAME" desc="The name of the Reload Frame command in the content area context menu">
Reload &amp;frame Reload &amp;frame
...@@ -763,6 +766,9 @@ are declared in build/common.gypi. ...@@ -763,6 +766,9 @@ are declared in build/common.gypi.
<message name="IDS_CONTENT_CONTEXT_TRANSLATE" desc="In Title Case: The name of the Translate command in the content area context menu"> <message name="IDS_CONTENT_CONTEXT_TRANSLATE" desc="In Title Case: The name of the Translate command in the content area context menu">
&amp;Translate to <ph name="LANGUAGE">$1<ex>English</ex></ph> &amp;Translate to <ph name="LANGUAGE">$1<ex>English</ex></ph>
</message> </message>
<message name="IDS_CONTENT_CONTEXT_EXIT_FULLSCREEN" desc="In Title Case: The name of the Exit Full Screen command in the content area context menu">
Exit Full Screen
</message>
<message name="IDS_CONTENT_CONTEXT_RELOADFRAME" desc="In Title Case: The name of the Reload Frame command in the content area context menu"> <message name="IDS_CONTENT_CONTEXT_RELOADFRAME" desc="In Title Case: The name of the Reload Frame command in the content area context menu">
Reload &amp;Frame Reload &amp;Frame
......
...@@ -306,9 +306,10 @@ const struct UmaEnumCommandIdPair { ...@@ -306,9 +306,10 @@ const struct UmaEnumCommandIdPair {
{85, -1, IDC_CONTENT_CONTEXT_OPEN_WITH12}, {85, -1, IDC_CONTENT_CONTEXT_OPEN_WITH12},
{86, -1, IDC_CONTENT_CONTEXT_OPEN_WITH13}, {86, -1, IDC_CONTENT_CONTEXT_OPEN_WITH13},
{87, -1, IDC_CONTENT_CONTEXT_OPEN_WITH14}, {87, -1, IDC_CONTENT_CONTEXT_OPEN_WITH14},
{88, -1, IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN},
// Add new items here and use |enum_id| from the next line. // Add new items here and use |enum_id| from the next line.
// Also, add new items to RenderViewContextMenuItem enum in histograms.xml. // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
{88, -1, 0}, // Must be the last. Increment |enum_id| when new IDC {89, -1, 0}, // Must be the last. Increment |enum_id| when new IDC
// was added. // was added.
}; };
...@@ -882,6 +883,16 @@ void RenderViewContextMenu::RecordShownItem(int id) { ...@@ -882,6 +883,16 @@ void RenderViewContextMenu::RecordShownItem(int id) {
} }
} }
bool RenderViewContextMenu::IsHTML5Fullscreen() const {
Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
if (!browser)
return false;
FullscreenController* controller =
browser->exclusive_access_manager()->fullscreen_controller();
return controller->IsTabFullscreen();
}
#if defined(ENABLE_PLUGINS) #if defined(ENABLE_PLUGINS)
void RenderViewContextMenu::HandleAuthorizeAllPlugins() { void RenderViewContextMenu::HandleAuthorizeAllPlugins() {
ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
...@@ -1170,6 +1181,8 @@ void RenderViewContextMenu::AppendPluginItems() { ...@@ -1170,6 +1181,8 @@ void RenderViewContextMenu::AppendPluginItems() {
} }
void RenderViewContextMenu::AppendPageItems() { void RenderViewContextMenu::AppendPageItems() {
AppendExitFullscreenItem();
menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK);
menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD);
menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD);
...@@ -1191,6 +1204,23 @@ void RenderViewContextMenu::AppendPageItems() { ...@@ -1191,6 +1204,23 @@ void RenderViewContextMenu::AppendPageItems() {
} }
} }
void RenderViewContextMenu::AppendExitFullscreenItem() {
Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
if (!browser)
return;
// Only show item if in fullscreen mode.
if (!browser->exclusive_access_manager()
->fullscreen_controller()
->IsControllerInitiatedFullscreen()) {
return;
}
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN,
IDS_CONTENT_CONTEXT_EXIT_FULLSCREEN);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
}
void RenderViewContextMenu::AppendCopyItem() { void RenderViewContextMenu::AppendCopyItem() {
if (menu_model_.GetItemCount()) if (menu_model_.GetItemCount())
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
...@@ -1581,6 +1611,9 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { ...@@ -1581,6 +1611,9 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
case IDC_ROUTE_MEDIA: case IDC_ROUTE_MEDIA:
return IsRouteMediaEnabled(); return IsRouteMediaEnabled();
case IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN:
return true;
default: default:
NOTREACHED(); NOTREACHED();
return false; return false;
...@@ -1754,6 +1787,10 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { ...@@ -1754,6 +1787,10 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
ExecRouteMedia(); ExecRouteMedia();
break; break;
case IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN:
ExecExitFullscreen();
break;
case IDC_VIEW_SOURCE: case IDC_VIEW_SOURCE:
embedder_web_contents_->ViewSource(); embedder_web_contents_->ViewSource();
break; break;
...@@ -2192,6 +2229,15 @@ void RenderViewContextMenu::ExecSaveAs() { ...@@ -2192,6 +2229,15 @@ void RenderViewContextMenu::ExecSaveAs() {
} }
} }
void RenderViewContextMenu::ExecExitFullscreen() {
Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
if (!browser) {
NOTREACHED();
return;
}
browser->exclusive_access_manager()->ExitExclusiveAccess();
}
void RenderViewContextMenu::ExecCopyLinkText() { void RenderViewContextMenu::ExecCopyLinkText() {
ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
......
...@@ -92,6 +92,10 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -92,6 +92,10 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
#endif #endif
void RecordUsedItem(int id) override; void RecordUsedItem(int id) override;
// Returns true if the browser is in HTML fullscreen mode, initiated by the
// page (as opposed to the user). Used to determine which shortcut to display.
bool IsHTML5Fullscreen() const;
private: private:
friend class RenderViewContextMenuTest; friend class RenderViewContextMenuTest;
friend class TestRenderViewContextMenu; friend class TestRenderViewContextMenu;
...@@ -131,6 +135,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -131,6 +135,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
void AppendMediaItems(); void AppendMediaItems();
void AppendPluginItems(); void AppendPluginItems();
void AppendPageItems(); void AppendPageItems();
void AppendExitFullscreenItem();
void AppendCopyItem(); void AppendCopyItem();
void AppendPrintItem(); void AppendPrintItem();
void AppendMediaRouterItem(); void AppendMediaRouterItem();
...@@ -169,6 +174,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -169,6 +174,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
void ExecInspectBackgroundPage(); void ExecInspectBackgroundPage();
void ExecSaveLinkAs(); void ExecSaveLinkAs();
void ExecSaveAs(); void ExecSaveAs();
void ExecExitFullscreen();
void ExecCopyLinkText(); void ExecCopyLinkText();
void ExecCopyImageAt(); void ExecCopyImageAt();
void ExecSearchWebForImage(); void ExecSearchWebForImage();
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/renderer_context_menu/views/toolkit_delegate_views.h" #include "components/renderer_context_menu/views/toolkit_delegate_views.h"
...@@ -63,6 +65,7 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId( ...@@ -63,6 +65,7 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId(
ui::Accelerator* accel) { ui::Accelerator* accel) {
// There are no formally defined accelerators we can query so we assume // There are no formally defined accelerators we can query so we assume
// that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do. // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
ui::AcceleratorProvider* accelerator_provider = nullptr;
switch (command_id) { switch (command_id) {
case IDC_BACK: case IDC_BACK:
*accel = ui::Accelerator(ui::VKEY_LEFT, ui::EF_ALT_DOWN); *accel = ui::Accelerator(ui::VKEY_LEFT, ui::EF_ALT_DOWN);
...@@ -129,6 +132,28 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId( ...@@ -129,6 +132,28 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId(
*accel = ui::Accelerator(ui::VKEY_S, ui::EF_CONTROL_DOWN); *accel = ui::Accelerator(ui::VKEY_S, ui::EF_CONTROL_DOWN);
return true; return true;
case IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN:
// Esc only works in HTML5 (site-triggered) fullscreen.
if (IsHTML5Fullscreen()) {
*accel = ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE);
return true;
}
#if defined(OS_CHROMEOS)
// Chromebooks typically do not have an F11 key, so do not show an
// accelerator here.
return false;
#endif
// User-triggered fullscreen. Show the shortcut for toggling fullscreen
// (i.e., F11).
accelerator_provider = GetBrowserAcceleratorProvider();
if (!accelerator_provider)
return false;
return accelerator_provider->GetAcceleratorForCommandId(IDC_FULLSCREEN,
accel);
case IDC_VIEW_SOURCE: case IDC_VIEW_SOURCE:
*accel = ui::Accelerator(ui::VKEY_U, ui::EF_CONTROL_DOWN); *accel = ui::Accelerator(ui::VKEY_U, ui::EF_CONTROL_DOWN);
return true; return true;
...@@ -200,6 +225,15 @@ bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const { ...@@ -200,6 +225,15 @@ bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const {
} }
} }
ui::AcceleratorProvider*
RenderViewContextMenuViews::GetBrowserAcceleratorProvider() const {
Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
if (!browser)
return nullptr;
return BrowserView::GetBrowserViewForBrowser(browser);
}
void RenderViewContextMenuViews::AppendPlatformEditableItems() { void RenderViewContextMenuViews::AppendPlatformEditableItems() {
bidi_submenu_model_.AddCheckItem( bidi_submenu_model_.AddCheckItem(
IDC_WRITING_DIRECTION_DEFAULT, IDC_WRITING_DIRECTION_DEFAULT,
......
...@@ -21,6 +21,10 @@ namespace views { ...@@ -21,6 +21,10 @@ namespace views {
class Widget; class Widget;
} }
namespace ui {
class AcceleratorProvider;
}
class RenderViewContextMenuViews : public RenderViewContextMenu { class RenderViewContextMenuViews : public RenderViewContextMenu {
public: public:
~RenderViewContextMenuViews() override; ~RenderViewContextMenuViews() override;
...@@ -52,6 +56,9 @@ class RenderViewContextMenuViews : public RenderViewContextMenu { ...@@ -52,6 +56,9 @@ class RenderViewContextMenuViews : public RenderViewContextMenu {
bool IsCommandIdChecked(int command_id) const override; bool IsCommandIdChecked(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override; bool IsCommandIdEnabled(int command_id) const override;
// Gets the AcceleratorProvider for the browser. May be null.
ui::AcceleratorProvider* GetBrowserAcceleratorProvider() const;
aura::Window* GetActiveNativeView(); aura::Window* GetActiveNativeView();
views::Widget* GetTopLevelWidget(); views::Widget* GetTopLevelWidget();
......
...@@ -88107,6 +88107,7 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -88107,6 +88107,7 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="85" label="IDC_CONTENT_CONTEXT_OPEN_WITH12"/> <int value="85" label="IDC_CONTENT_CONTEXT_OPEN_WITH12"/>
<int value="86" label="IDC_CONTENT_CONTEXT_OPEN_WITH13"/> <int value="86" label="IDC_CONTENT_CONTEXT_OPEN_WITH13"/>
<int value="87" label="IDC_CONTENT_CONTEXT_OPEN_WITH14"/> <int value="87" label="IDC_CONTENT_CONTEXT_OPEN_WITH14"/>
<int value="88" label="IDC_CONTENT_CONTEXT_EXIT_FULLSCREEN"/>
</enum> </enum>
<enum name="ReportProcessingResult" type="int"> <enum name="ReportProcessingResult" type="int">
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