Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enable keyboard shortcuts and some menu commands for browserless Panels.

Prevent context menu in Panels.

BUG=127323
TEST=open panels and try various shortcuts and menu commands

Review URL: https://chromiumcodereview.appspot.com/10736037

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@146580 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit 564db6f975e8d879a705f4030d5c365bd6fe5cf6 1 parent 9b597b1
jennb@chromium.org authored
View
58 chrome_page_zoom.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -8,9 +8,14 @@
#include <cmath>
#include "chrome/browser/chrome_page_zoom_constants.h"
-#include "content/public/common/page_zoom.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/renderer_preferences.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+using content::UserMetricsAction;
+
namespace chrome_page_zoom {
enum PageZoomValueType {
@@ -56,4 +61,53 @@ std::vector<double> PresetZoomLevels(double custom_level) {
return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
}
+void Zoom(content::WebContents* web_contents, content::PageZoom zoom) {
+ content::RenderViewHost* host = web_contents->GetRenderViewHost();
+ if (zoom == content::PAGE_ZOOM_RESET) {
+ host->SetZoomLevel(0);
+ content::RecordAction(UserMetricsAction("ZoomNormal"));
+ return;
+ }
+
+ double current_zoom_level = web_contents->GetZoomLevel();
+ double default_zoom_level =
+ web_contents->GetMutableRendererPrefs()->default_zoom_level;
+
+ // Generate a vector of zoom levels from an array of known presets along with
+ // the default level added if necessary.
+ std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level);
+
+ if (zoom == content::PAGE_ZOOM_OUT) {
+ // Iterate through the zoom levels in reverse order to find the next
+ // lower level based on the current zoom level for this page.
+ for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin();
+ i != zoom_levels.rend(); ++i) {
+ double zoom_level = *i;
+ if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
+ continue;
+ if (zoom_level < current_zoom_level) {
+ host->SetZoomLevel(zoom_level);
+ content::RecordAction(UserMetricsAction("ZoomMinus"));
+ return;
+ }
+ content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum"));
+ }
+ } else {
+ // Iterate through the zoom levels in normal order to find the next
+ // higher level based on the current zoom level for this page.
+ for (std::vector<double>::const_iterator i = zoom_levels.begin();
+ i != zoom_levels.end(); ++i) {
+ double zoom_level = *i;
+ if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
+ continue;
+ if (zoom_level > current_zoom_level) {
+ host->SetZoomLevel(zoom_level);
+ content::RecordAction(UserMetricsAction("ZoomPlus"));
+ return;
+ }
+ }
+ content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum"));
+ }
+}
+
} // namespace chrome_page_zoom
View
10 chrome_page_zoom.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -6,6 +6,11 @@
#define CHROME_BROWSER_CHROME_PAGE_ZOOM_H_
#include <vector>
+#include "content/public/common/page_zoom.h"
+
+namespace content {
+class WebContents;
+}
namespace chrome_page_zoom {
@@ -19,6 +24,9 @@ std::vector<double> PresetZoomFactors(double custom_factor);
// represented.)
std::vector<double> PresetZoomLevels(double custom_level);
+// Adjusts the zoom level of |web_contents|.
+void Zoom(content::WebContents* web_contents, content::PageZoom zoom);
+
} // namespace chrome_page_zoom
#endif // CHROME_BROWSER_CHROME_PAGE_ZOOM_H_
View
49 ui/browser_commands.cc
@@ -763,54 +763,7 @@ void Zoom(Browser* browser, content::PageZoom zoom) {
if (browser->is_devtools())
return;
- content::RenderViewHost* host =
- GetActiveWebContents(browser)->GetRenderViewHost();
- if (zoom == content::PAGE_ZOOM_RESET) {
- host->SetZoomLevel(0);
- content::RecordAction(UserMetricsAction("ZoomNormal"));
- return;
- }
-
- double current_zoom_level = GetActiveWebContents(browser)->GetZoomLevel();
- double default_zoom_level =
- browser->profile()->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
-
- // Generate a vector of zoom levels from an array of known presets along with
- // the default level added if necessary.
- std::vector<double> zoom_levels =
- chrome_page_zoom::PresetZoomLevels(default_zoom_level);
-
- if (zoom == content::PAGE_ZOOM_OUT) {
- // Iterate through the zoom levels in reverse order to find the next
- // lower level based on the current zoom level for this page.
- for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin();
- i != zoom_levels.rend(); ++i) {
- double zoom_level = *i;
- if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
- continue;
- if (zoom_level < current_zoom_level) {
- host->SetZoomLevel(zoom_level);
- content::RecordAction(UserMetricsAction("ZoomMinus"));
- return;
- }
- content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum"));
- }
- } else {
- // Iterate through the zoom levels in normal order to find the next
- // higher level based on the current zoom level for this page.
- for (std::vector<double>::const_iterator i = zoom_levels.begin();
- i != zoom_levels.end(); ++i) {
- double zoom_level = *i;
- if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
- continue;
- if (zoom_level > current_zoom_level) {
- host->SetZoomLevel(zoom_level);
- content::RecordAction(UserMetricsAction("ZoomPlus"));
- return;
- }
- }
- content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum"));
- }
+ chrome_page_zoom::Zoom(GetActiveWebContents(browser), zoom);
}
void FocusToolbar(Browser* browser) {
View
46 ui/panels/panel.cc
@@ -23,11 +23,13 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/rect.h"
using content::RenderViewHost;
+using content::UserMetricsAction;
namespace panel_internal {
@@ -317,6 +319,10 @@ gfx::Size Panel::ClampSize(const gfx::Size& size) const {
return gfx::Size(new_width, new_height);
}
+void Panel::HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event) {
+ native_panel_->HandlePanelKeyboardEvent(event);
+}
+
void Panel::SetAlwaysOnTop(bool on_top) {
if (always_on_top_ == on_top)
return;
@@ -520,8 +526,42 @@ void Panel::ExecuteCommandWithDisposition(int id,
DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
<< id;
switch (id) {
- case IDC_RELOAD: // etc
- // TODO(jennb): implement.
+ // Navigation
+ case IDC_RELOAD:
+ panel_host_->Reload();
+ break;
+ case IDC_RELOAD_IGNORING_CACHE:
+ panel_host_->ReloadIgnoringCache();
+ break;
+ case IDC_STOP:
+ panel_host_->StopLoading();
+ break;
+
+ // Clipboard
+ case IDC_COPY:
+ content::RecordAction(UserMetricsAction("Copy"));
+ native_panel_->PanelCopy();
+ break;
+ case IDC_CUT:
+ content::RecordAction(UserMetricsAction("Cut"));
+ native_panel_->PanelCut();
+ break;
+ case IDC_PASTE:
+ content::RecordAction(UserMetricsAction("Paste"));
+ native_panel_->PanelPaste();
+ break;
+
+ // Zoom
+ case IDC_ZOOM_PLUS:
+ panel_host_->Zoom(content::PAGE_ZOOM_IN);
+ break;
+ case IDC_ZOOM_NORMAL:
+ panel_host_->Zoom(content::PAGE_ZOOM_RESET);
+ break;
+ case IDC_ZOOM_MINUS:
+ panel_host_->Zoom(content::PAGE_ZOOM_OUT);
+ break;
+
default:
LOG(WARNING) << "Received unimplemented command: " << id;
break;
@@ -681,7 +721,7 @@ void Panel::UpdateTitleBar() {
}
void Panel::LoadingStateChanged(bool is_loading) {
+ command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
native_panel_->UpdatePanelLoadingAnimations(is_loading);
UpdateTitleBar();
- command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
}
View
4 ui/panels/panel.h
@@ -31,6 +31,7 @@ class SkBitmap;
namespace content {
class WebContents;
+struct NativeWebKeyboardEvent;
}
// A platform independent implementation of BaseWindow for Panels.
@@ -244,6 +245,9 @@ class Panel : public BaseWindow,
// user-resizable, it should not be a problem.
void IncreaseMaxSize(const gfx::Size& desired_panel_size);
+ // Handles keyboard events coming back from the renderer.
+ void HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event);
+
// Whether the panel window is always on top.
void SetAlwaysOnTop(bool on_top);
bool always_on_top() const { return always_on_top_; }
View
10 ui/panels/panel_cocoa.mm
@@ -199,13 +199,19 @@
bool PanelCocoa::PreHandlePanelKeyboardEvent(
const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
- // TODO(jennb): any shortcut handling needed for Panel?
+ // No need to prehandle as no keys are reserved.
return false;
}
void PanelCocoa::HandlePanelKeyboardEvent(
const NativeWebKeyboardEvent& event) {
- // TODO(jennb): any shortcut handling needed for Panel?
+ if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
+ return;
+
+ ChromeEventProcessingWindow* event_window =
+ static_cast<ChromeEventProcessingWindow*>([controller_ window]);
+ DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
+ [event_window redispatchKeyEvent:event.os_event];
}
void PanelCocoa::FullScreenModeChanged(
View
36 ui/panels/panel_host.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "chrome/browser/chrome_page_zoom.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/panels/panel.h"
@@ -19,12 +20,15 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
+#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/rect.h"
+using content::UserMetricsAction;
+
PanelHost::PanelHost(Panel* panel, Profile* profile)
: panel_(panel),
profile_(profile),
@@ -96,10 +100,23 @@ bool PanelHost::IsPopupOrPanel(const content::WebContents* source) const {
return true;
}
+void PanelHost::ContentsZoomChange(bool zoom_in) {
+ Zoom(zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
+}
+
bool PanelHost::IsApplication() const {
return true;
}
+bool PanelHost::HandleContextMenu(const content::ContextMenuParams& params) {
+ return true; // Disallow context menu.
+}
+
+void PanelHost::HandleKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) {
+ return panel_->HandleKeyboardEvent(event);
+}
+
void PanelHost::ResizeDueToAutoResize(content::WebContents* web_contents,
const gfx::Size& new_size) {
panel_->OnContentsAutoResized(new_size);
@@ -146,3 +163,22 @@ ExtensionWindowController* PanelHost::GetExtensionWindowController() const {
content::WebContents* PanelHost::GetAssociatedWebContents() const {
return web_contents_.get();
}
+
+void PanelHost::Reload() {
+ content::RecordAction(UserMetricsAction("Reload"));
+ web_contents_->GetController().Reload(true);
+}
+
+void PanelHost::ReloadIgnoringCache() {
+ content::RecordAction(UserMetricsAction("ReloadIgnoringCache"));
+ web_contents_->GetController().ReloadIgnoringCache(true);
+}
+
+void PanelHost::StopLoading() {
+ content::RecordAction(UserMetricsAction("Stop"));
+ web_contents_->Stop();
+}
+
+void PanelHost::Zoom(content::PageZoom zoom) {
+ chrome_page_zoom::Zoom(web_contents_.get(), zoom);
+}
View
12 ui/panels/panel_host.h
@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/page_zoom.h"
class ExtensionWindowController;
class FaviconTabHelper;
@@ -52,7 +53,12 @@ class PanelHost : public content::WebContentsDelegate,
const gfx::Rect& pos) OVERRIDE;
virtual bool IsPopupOrPanel(
const content::WebContents* source) const OVERRIDE;
+ virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
virtual bool IsApplication() const OVERRIDE;
+ virtual bool HandleContextMenu(
+ const content::ContextMenuParams& params) OVERRIDE;
+ virtual void HandleKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
const gfx::Size& new_size) OVERRIDE;
@@ -67,6 +73,12 @@ class PanelHost : public content::WebContentsDelegate,
OVERRIDE;
virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
+ // Actions on web contents.
+ void Reload();
+ void ReloadIgnoringCache();
+ void StopLoading();
+ void Zoom(content::PageZoom zoom);
+
private:
// Helper to close panel via the message loop.
void ClosePanel();
Please sign in to comment.
Something went wrong with that request. Please try again.