Commit 7f6f1953 authored by skuhne@chromium.org's avatar skuhne@chromium.org

Adding four bezel gestures


BUG=126061, 126060, 123167
TEST=Unit test


Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=137968

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138000 0039d316-1c4b-4281-b951-d872f2087c98
parent 1c9515bb
...@@ -77,6 +77,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { ...@@ -77,6 +77,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
return brightness_control_delegate_.get(); return brightness_control_delegate_.get();
} }
VolumeControlDelegate* volume_control_delegate() const {
return volume_control_delegate_.get();
}
private: private:
// Initializes the accelerators this class handles as a target. // Initializes the accelerators this class handles as a target.
void Init(); void Init();
......
...@@ -142,6 +142,8 @@ class DummyVolumeControlDelegate : public VolumeControlDelegate { ...@@ -142,6 +142,8 @@ class DummyVolumeControlDelegate : public VolumeControlDelegate {
last_accelerator_ = accelerator; last_accelerator_ = accelerator;
return consume_; return consume_;
} }
virtual void SetVolumePercent(double percent) OVERRIDE {
}
int handle_volume_mute_count() const { int handle_volume_mute_count() const {
return handle_volume_mute_count_; return handle_volume_mute_count_;
......
...@@ -26,12 +26,19 @@ TestLauncherDelegate::~TestLauncherDelegate() { ...@@ -26,12 +26,19 @@ TestLauncherDelegate::~TestLauncherDelegate() {
} }
void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { void TestLauncherDelegate::AddLauncherItem(aura::Window* window) {
AddLauncherItem(window, STATUS_CLOSED);
}
void TestLauncherDelegate::AddLauncherItem(
aura::Window* window,
LauncherItemStatus status) {
ash::LauncherItem item; ash::LauncherItem item;
item.type = ash::TYPE_TABBED; item.type = ash::TYPE_TABBED;
DCHECK(window_to_id_.find(window) == window_to_id_.end()); DCHECK(window_to_id_.find(window) == window_to_id_.end());
window_to_id_[window] = model_->next_id(); window_to_id_[window] = model_->next_id();
item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
item.image.allocPixels(); item.image.allocPixels();
item.status = status;
model_->Add(item); model_->Add(item);
if (observed_windows_.find(window->parent()) == observed_windows_.end()) { if (observed_windows_.find(window->parent()) == observed_windows_.end()) {
window->parent()->AddObserver(this); window->parent()->AddObserver(this);
......
...@@ -28,6 +28,7 @@ class TestLauncherDelegate : public LauncherDelegate, ...@@ -28,6 +28,7 @@ class TestLauncherDelegate : public LauncherDelegate,
virtual ~TestLauncherDelegate(); virtual ~TestLauncherDelegate();
void AddLauncherItem(aura::Window* window); void AddLauncherItem(aura::Window* window);
void AddLauncherItem(aura::Window* window, LauncherItemStatus status);
static TestLauncherDelegate* instance() { return instance_; } static TestLauncherDelegate* instance() { return instance_; }
......
...@@ -20,6 +20,10 @@ class VolumeControlDelegate { ...@@ -20,6 +20,10 @@ class VolumeControlDelegate {
virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) = 0; virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) = 0;
virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) = 0; virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) = 0;
virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) = 0; virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) = 0;
// Requests that the volume be set to |percent|, in the range
// [0.0, 100.0].
virtual void SetVolumePercent(double percent) = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -5,14 +5,22 @@ ...@@ -5,14 +5,22 @@
#include "ash/wm/system_gesture_event_filter.h" #include "ash/wm/system_gesture_event_filter.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/system/brightness/brightness_control_delegate.h"
#include "ash/volume_control_delegate.h"
#include "ui/aura/event.h" #include "ui/aura/event.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
#include "ui/gfx/screen.h"
namespace ash { namespace ash {
namespace internal { namespace internal {
SystemGestureEventFilter::SystemGestureEventFilter() SystemGestureEventFilter::SystemGestureEventFilter()
: aura::EventFilter() { : aura::EventFilter(),
overlap_percent_(5),
start_location_(BEZEL_START_UNSET),
orientation_(SCROLL_ORIENTATION_UNSET),
is_scrubbing_(false){
} }
SystemGestureEventFilter::~SystemGestureEventFilter() { SystemGestureEventFilter::~SystemGestureEventFilter() {
...@@ -39,10 +47,121 @@ ui::GestureStatus SystemGestureEventFilter::PreHandleGestureEvent( ...@@ -39,10 +47,121 @@ ui::GestureStatus SystemGestureEventFilter::PreHandleGestureEvent(
// TODO(tdresser) handle system level gesture events // TODO(tdresser) handle system level gesture events
if (event->type() == ui::ET_GESTURE_THREE_FINGER_SWIPE) if (event->type() == ui::ET_GESTURE_THREE_FINGER_SWIPE)
return ui::GESTURE_STATUS_CONSUMED; return ui::GESTURE_STATUS_CONSUMED;
if (target == Shell::GetRootWindow()) if (!target || target == Shell::GetRootWindow()) {
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN: {
gfx::Rect screen =
gfx::Screen::GetPrimaryMonitor().bounds();
int overlap_area = screen.width() * overlap_percent_ / 100;
orientation_ = SCROLL_ORIENTATION_UNSET;
if (event->x() <= screen.x() + overlap_area) {
start_location_ = BEZEL_START_LEFT;
} else if (event->x() >= screen.right() - overlap_area) {
start_location_ = BEZEL_START_RIGHT;
} else if (event->y() >= screen.bottom()) {
start_location_ = BEZEL_START_BOTTOM;
}
}
break;
case ui::ET_GESTURE_SCROLL_UPDATE:
if (start_location_ == BEZEL_START_UNSET)
break;
if (orientation_ == SCROLL_ORIENTATION_UNSET) {
if (!event->delta_x() && !event->delta_y())
break;
// For left and right the scroll angle needs to be much steeper to
// be accepted for a 'device configuration' gesture.
if (start_location_ == BEZEL_START_LEFT ||
start_location_ == BEZEL_START_RIGHT) {
orientation_ = abs(event->delta_y()) > abs(event->delta_x()) * 3 ?
SCROLL_ORIENTATION_VERTICAL : SCROLL_ORIENTATION_HORIZONTAL;
} else {
orientation_ = abs(event->delta_y()) > abs(event->delta_x()) ?
SCROLL_ORIENTATION_VERTICAL : SCROLL_ORIENTATION_HORIZONTAL;
}
}
if (orientation_ == SCROLL_ORIENTATION_HORIZONTAL) {
if (HandleApplicationControl(event))
start_location_ = BEZEL_START_UNSET;
} else {
if (start_location_ == BEZEL_START_BOTTOM) {
if (HandleLauncherControl(event))
start_location_ = BEZEL_START_UNSET;
} else {
if (HandleDeviceControl(event))
start_location_ = BEZEL_START_UNSET;
}
}
break;
case ui::ET_GESTURE_SCROLL_END:
start_location_ = BEZEL_START_UNSET;
break;
default:
break;
}
return ui::GESTURE_STATUS_CONSUMED; return ui::GESTURE_STATUS_CONSUMED;
}
return ui::GESTURE_STATUS_UNKNOWN; return ui::GESTURE_STATUS_UNKNOWN;
} }
bool SystemGestureEventFilter::HandleDeviceControl(aura::GestureEvent* event) {
gfx::Rect screen = gfx::Screen::GetPrimaryMonitor().bounds();
double percent = 100.0 * (event->y() - screen.y()) / screen.height();
if (percent > 100.0)
percent = 100.0;
if (percent < 0.0)
percent = 0.0;
ash::AcceleratorController* accelerator =
ash::Shell::GetInstance()->accelerator_controller();
if (start_location_ == BEZEL_START_LEFT) {
ash::BrightnessControlDelegate* delegate =
accelerator->brightness_control_delegate();
if (delegate)
delegate->SetBrightnessPercent(100.0 - percent, true);
} else if (start_location_ == BEZEL_START_RIGHT) {
ash::VolumeControlDelegate* delegate =
accelerator->volume_control_delegate();
if (delegate)
delegate->SetVolumePercent(100.0 - percent);
} else {
return true;
}
// More notifications can be send.
return false;
}
bool SystemGestureEventFilter::HandleLauncherControl(
aura::GestureEvent* event) {
ash::AcceleratorController* accelerator =
ash::Shell::GetInstance()->accelerator_controller();
if (start_location_ == BEZEL_START_BOTTOM && event->delta_y() < 0)
// We leave the work to switch to the next window to our accelerators.
accelerator->AcceleratorPressed(
ui::Accelerator(ui::VKEY_LWIN, ui::EF_CONTROL_DOWN));
else
return false;
// No further notifications for this gesture.
return true;
}
bool SystemGestureEventFilter::HandleApplicationControl(
aura::GestureEvent* event) {
ash::AcceleratorController* accelerator =
ash::Shell::GetInstance()->accelerator_controller();
if (start_location_ == BEZEL_START_LEFT && event->delta_x() > 0)
// We leave the work to switch to the next window to our accelerators.
accelerator->AcceleratorPressed(
ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN));
else if (start_location_ == BEZEL_START_RIGHT && event->delta_x() < 0)
// We leave the work to switch to the previous window to our accelerators.
accelerator->AcceleratorPressed(
ui::Accelerator(ui::VKEY_F5, ui::EF_NONE));
else
return false;
// No further notifications for this gesture.
return true;
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
...@@ -18,6 +18,20 @@ class Window; ...@@ -18,6 +18,20 @@ class Window;
namespace ash { namespace ash {
namespace internal { namespace internal {
enum BezelStart {
BEZEL_START_UNSET = 0,
BEZEL_START_TOP,
BEZEL_START_LEFT,
BEZEL_START_RIGHT,
BEZEL_START_BOTTOM
};
enum ScrollOrientation {
SCROLL_ORIENTATION_UNSET = 0,
SCROLL_ORIENTATION_HORIZONTAL,
SCROLL_ORIENTATION_VERTICAL
};
// An event filter which handles system level gesture events. // An event filter which handles system level gesture events.
class SystemGestureEventFilter : public aura::EventFilter { class SystemGestureEventFilter : public aura::EventFilter {
public: public:
...@@ -36,6 +50,31 @@ class SystemGestureEventFilter : public aura::EventFilter { ...@@ -36,6 +50,31 @@ class SystemGestureEventFilter : public aura::EventFilter {
aura::GestureEvent* event) OVERRIDE; aura::GestureEvent* event) OVERRIDE;
private: private:
// Handle events meant for volume / brightness. Returns true when no further
// events from this gesture should be sent.
bool HandleDeviceControl(aura::GestureEvent* event);
// Handle events meant for showing the launcher. Returns true when no further
// events from this gesture should be sent.
bool HandleLauncherControl(aura::GestureEvent* event);
// Handle events meant to switch through applications. Returns true when no
// further events from this gesture should be sent.
bool HandleApplicationControl(aura::GestureEvent* event);
// The percentage of the screen to the left and right which belongs to
// device gestures.
const int overlap_percent_;
// Which bezel corner are we on.
BezelStart start_location_;
// Which orientation are we moving.
ScrollOrientation orientation_;
// A device swipe gesture is in progress.
bool is_scrubbing_;
DISALLOW_COPY_AND_ASSIGN(SystemGestureEventFilter); DISALLOW_COPY_AND_ASSIGN(SystemGestureEventFilter);
}; };
......
...@@ -68,3 +68,13 @@ bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { ...@@ -68,3 +68,13 @@ bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) {
audio_handler->IsMuted()); audio_handler->IsMuted());
return true; return true;
} }
void VolumeController::SetVolumePercent(double percent) {
chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
if (audio_handler->IsMuted()) {
audio_handler->SetMuted(false);
}
audio_handler->SetVolumePercent(percent);
extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(),
audio_handler->IsMuted());
}
...@@ -21,6 +21,7 @@ class VolumeController : public ash::VolumeControlDelegate { ...@@ -21,6 +21,7 @@ class VolumeController : public ash::VolumeControlDelegate {
virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE; virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE;
virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE; virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE;
virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE; virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE;
virtual void SetVolumePercent(double percent) OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(VolumeController); DISALLOW_COPY_AND_ASSIGN(VolumeController);
......
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