Commit 411f87ce authored by oshima@chromium.org's avatar oshima@chromium.org

Simplify AcceleratorDelegate interface

BUG=None
TEST=no functional change.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274035 0039d316-1c4b-4281-b951-d872f2087c98
parent 36fc8174
...@@ -27,6 +27,24 @@ void AcceleratorDelegate::PreProcessAccelerator( ...@@ -27,6 +27,24 @@ void AcceleratorDelegate::PreProcessAccelerator(
accelerator); accelerator);
} }
bool AcceleratorDelegate::ProcessAccelerator(const ui::KeyEvent& key_event,
const ui::Accelerator& accelerator,
KeyType key_type) {
// Special hardware keys like brightness and volume are handled in
// special way. However, some windows can override this behavior
// (e.g. Chrome v1 apps by default and Chrome v2 apps with
// permission) by setting a window property.
if (key_type == KEY_TYPE_SYSTEM && !CanConsumeSystemKeys(key_event)) {
// System keys are always consumed regardless of whether they trigger an
// accelerator to prevent windows from seeing unexpected key up events.
Shell::GetInstance()->accelerator_controller()->Process(accelerator);
return true;
}
if (!ShouldProcessAcceleratorNow(key_event, accelerator))
return false;
return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
}
// Uses the top level window so if the target is a web contents window the // Uses the top level window so if the target is a web contents window the
// containing parent window will be checked for the property. // containing parent window will be checked for the property.
bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) { bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) {
...@@ -53,7 +71,9 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow( ...@@ -53,7 +71,9 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
// A full screen window should be able to handle all key events including the // A full screen window should be able to handle all key events including the
// reserved ones. // reserved ones.
if (wm::GetWindowState(target)->IsFullscreen()) { aura::Window* top_level = ::wm::GetToplevelWindow(target);
if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) {
// TODO(yusukes): On Chrome OS, only browser and flash windows can be full // TODO(yusukes): On Chrome OS, only browser and flash windows can be full
// screen. Launching an app in "open full-screen" mode is not supported yet. // screen. Launching an app in "open full-screen" mode is not supported yet.
// That makes the IsWindowFullscreen() check above almost meaningless // That makes the IsWindowFullscreen() check above almost meaningless
...@@ -71,9 +91,4 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow( ...@@ -71,9 +91,4 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
accelerator); accelerator);
} }
bool AcceleratorDelegate::ProcessAccelerator(
const ui::Accelerator& accelerator) {
return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
}
} // namespace ash } // namespace ash
...@@ -20,13 +20,18 @@ class ASH_EXPORT AcceleratorDelegate ...@@ -20,13 +20,18 @@ class ASH_EXPORT AcceleratorDelegate
// wm::AcceleratorDelegate: // wm::AcceleratorDelegate:
virtual void PreProcessAccelerator( virtual void PreProcessAccelerator(
const ui::Accelerator& accelerator) OVERRIDE; const ui::Accelerator& accelerator) OVERRIDE;
virtual bool CanConsumeSystemKeys(const ui::KeyEvent& event) OVERRIDE; virtual bool ProcessAccelerator(const ui::KeyEvent& event,
virtual bool ShouldProcessAcceleratorNow( const ui::Accelerator& accelerator,
const ui::KeyEvent& key_event, KeyType key_type) OVERRIDE;
const ui::Accelerator& accelerator) OVERRIDE;
virtual bool ProcessAccelerator(const ui::Accelerator& accelerator) OVERRIDE;
private: private:
// Returns true if the window should be allowed a chance to handle
// system keys.
bool CanConsumeSystemKeys(const ui::KeyEvent& event);
bool ShouldProcessAcceleratorNow(const ui::KeyEvent& event,
const ui::Accelerator& accelerator);
DISALLOW_COPY_AND_ASSIGN(AcceleratorDelegate); DISALLOW_COPY_AND_ASSIGN(AcceleratorDelegate);
}; };
......
...@@ -16,20 +16,19 @@ class AcceleratorDelegate { ...@@ -16,20 +16,19 @@ class AcceleratorDelegate {
public: public:
virtual ~AcceleratorDelegate() {} virtual ~AcceleratorDelegate() {}
// Type of keys that triggers accelerators.
enum KeyType {
KEY_TYPE_SYSTEM,
KEY_TYPE_OTHER,
};
// TODO(oshima): Move the repeat detection to AcceleratorFilter. // TODO(oshima): Move the repeat detection to AcceleratorFilter.
virtual void PreProcessAccelerator(const ui::Accelerator& accelerator) = 0; virtual void PreProcessAccelerator(const ui::Accelerator& accelerator) = 0;
// Returns true if the window should be allowed a chance to handle
// system keys.
virtual bool CanConsumeSystemKeys(const ui::KeyEvent& event) = 0;
// Returns true if the |accelerator| should be processed.
virtual bool ShouldProcessAcceleratorNow(
const ui::KeyEvent& key_event,
const ui::Accelerator& accelerator) = 0;
// Return true if the |accelerator| has been processed. // Return true if the |accelerator| has been processed.
virtual bool ProcessAccelerator(const ui::Accelerator& accelerator) = 0; virtual bool ProcessAccelerator(const ui::KeyEvent& event,
const ui::Accelerator& accelerator,
KeyType key_type) = 0;
}; };
} // namespace wm } // namespace wm
......
...@@ -52,10 +52,10 @@ AcceleratorFilter::~AcceleratorFilter() { ...@@ -52,10 +52,10 @@ AcceleratorFilter::~AcceleratorFilter() {
void AcceleratorFilter::OnKeyEvent(ui::KeyEvent* event) { void AcceleratorFilter::OnKeyEvent(ui::KeyEvent* event) {
const ui::EventType type = event->type(); const ui::EventType type = event->type();
if (type != ui::ET_KEY_PRESSED && type != ui::ET_KEY_RELEASED) if ((type != ui::ET_KEY_PRESSED && type != ui::ET_KEY_RELEASED) ||
return; event->is_char()) {
if (event->is_char())
return; return;
}
ui::Accelerator accelerator(event->key_code(), ui::Accelerator accelerator(event->key_code(),
event->flags() & kModifierFlagMask); event->flags() & kModifierFlagMask);
...@@ -63,22 +63,11 @@ void AcceleratorFilter::OnKeyEvent(ui::KeyEvent* event) { ...@@ -63,22 +63,11 @@ void AcceleratorFilter::OnKeyEvent(ui::KeyEvent* event) {
delegate_->PreProcessAccelerator(accelerator); delegate_->PreProcessAccelerator(accelerator);
// Handle special hardware keys like brightness and volume. However, some AcceleratorDelegate::KeyType key_type =
// windows can override this behavior (e.g. Chrome v1 apps by default and IsSystemKey(event->key_code()) ? AcceleratorDelegate::KEY_TYPE_SYSTEM
// Chrome v2 apps with permission) by setting a window property. : AcceleratorDelegate::KEY_TYPE_OTHER;
if (IsSystemKey(event->key_code()) &&
!delegate_->CanConsumeSystemKeys(*event)) {
delegate_->ProcessAccelerator(accelerator);
// These keys are always consumed regardless of whether they trigger an
// accelerator to prevent windows from seeing unexpected key up events.
event->StopPropagation();
return;
}
if (!delegate_->ShouldProcessAcceleratorNow(*event, accelerator))
return;
if (delegate_->ProcessAccelerator(accelerator)) if (delegate_->ProcessAccelerator(*event, accelerator, key_type))
event->StopPropagation(); event->StopPropagation();
} }
......
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