diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 15:47:16 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 15:47:16 +0000 |
commit | 8a1527ba318b957ba41c484d3c45eaae93ec35ff (patch) | |
tree | c466ea88c62b57cda3cbdb566329533b37cbafe9 /ui/aura | |
parent | 61ede748570cf4495bba507a57f47cc6a664a1e1 (diff) | |
download | chromium_src-8a1527ba318b957ba41c484d3c45eaae93ec35ff.zip chromium_src-8a1527ba318b957ba41c484d3c45eaae93ec35ff.tar.gz chromium_src-8a1527ba318b957ba41c484d3c45eaae93ec35ff.tar.bz2 |
Adds support for fullscreening the desktop host on Windows. F11.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8440052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/desktop.cc | 80 | ||||
-rw-r--r-- | ui/aura/desktop_host.h | 3 | ||||
-rw-r--r-- | ui/aura/desktop_host_linux.cc | 5 | ||||
-rw-r--r-- | ui/aura/desktop_host_win.cc | 38 | ||||
-rw-r--r-- | ui/aura/desktop_host_win.h | 6 |
5 files changed, 99 insertions, 33 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc index e6edb30..07edd11 100644 --- a/ui/aura/desktop.cc +++ b/ui/aura/desktop.cc @@ -159,6 +159,50 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) { } } +bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { + if (event->key_code() == ui::VKEY_F11) { + host->ToggleFullScreen(); + return true; + } + return false; +} + +bool MaybeRotate(Desktop* desktop, KeyEvent* event) { + if ((event->flags() & ui::EF_SHIFT_DOWN) && + (event->flags() & ui::EF_ALT_DOWN)) { + bool should_rotate = true; + int new_degrees = 0; + switch (event->key_code()) { + case ui::VKEY_UP: new_degrees = 0; break; + case ui::VKEY_DOWN: new_degrees = 180; break; + case ui::VKEY_RIGHT: new_degrees = 90; break; + case ui::VKEY_LEFT: new_degrees = -90; break; + default: should_rotate = false; break; + } + + if (should_rotate) { + float rotation = 0.0f; + int degrees = 0; + const ui::Transform& transform = desktop->layer()->GetTargetTransform(); + if (ui::InterpolatedTransform::FactorTRS(transform, + NULL, &rotation, NULL)) + degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation)); + + if (degrees != 0) { + desktop->layer()->GetAnimator()->set_preemption_strategy( + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); + scoped_ptr<ui::LayerAnimationSequence> screen_rotation( + new ui::LayerAnimationSequence(new ScreenRotation(degrees))); + screen_rotation->AddObserver(desktop); + desktop->layer()->GetAnimator()->ScheduleAnimation( + screen_rotation.release()); + return true; + } + } + } + return false; +} + } // namespace Desktop* Desktop::instance_ = NULL; @@ -279,38 +323,10 @@ bool Desktop::DispatchMouseEvent(MouseEvent* event) { bool Desktop::DispatchKeyEvent(KeyEvent* event) { #if !defined(NDEBUG) - if (event->type() == ui::ET_KEY_PRESSED && - (event->flags() & ui::EF_SHIFT_DOWN) && - (event->flags() & ui::EF_ALT_DOWN)) { - - bool should_rotate = true; - int new_degrees = 0; - switch (event->key_code()) { - case ui::VKEY_UP: new_degrees = 0; break; - case ui::VKEY_DOWN: new_degrees = 180; break; - case ui::VKEY_RIGHT: new_degrees = 90; break; - case ui::VKEY_LEFT: new_degrees = -90; break; - default: should_rotate = false; break; - } - - if (should_rotate) { - float rotation = 0.0f; - int degrees = 0; - const ui::Transform& transform = layer()->GetTargetTransform(); - if (ui::InterpolatedTransform::FactorTRS(transform, - NULL, &rotation, NULL)) - degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation)); - - if (degrees != 0) { - layer()->GetAnimator()->set_preemption_strategy( - ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); - scoped_ptr<ui::LayerAnimationSequence> screen_rotation( - new ui::LayerAnimationSequence(new ScreenRotation(degrees))); - screen_rotation->AddObserver(this); - layer()->GetAnimator()->ScheduleAnimation(screen_rotation.release()); - return true; - } - } + // TODO(beng): replace this hack with global keyboard event handlers. + if (event->type() == ui::ET_KEY_PRESSED) { + if (MaybeFullScreen(host_.get(), event) || MaybeRotate(this, event)) + return true; } #endif diff --git a/ui/aura/desktop_host.h b/ui/aura/desktop_host.h index 983eea2..06f6fe3 100644 --- a/ui/aura/desktop_host.h +++ b/ui/aura/desktop_host.h @@ -43,6 +43,9 @@ class DesktopHost : public MessageLoop::Dispatcher { // Shows the DesktopHost. virtual void Show() = 0; + // Toggles the host's full screen state. + virtual void ToggleFullScreen() = 0; + // Gets/Sets the size of the DesktopHost. virtual gfx::Size GetSize() const = 0; virtual void SetSize(const gfx::Size& size) = 0; diff --git a/ui/aura/desktop_host_linux.cc b/ui/aura/desktop_host_linux.cc index 254f43b..875f39d 100644 --- a/ui/aura/desktop_host_linux.cc +++ b/ui/aura/desktop_host_linux.cc @@ -234,6 +234,7 @@ class DesktopHostLinux : public DesktopHost { virtual void SetDesktop(Desktop* desktop) OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; + virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Size GetSize() const OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; @@ -423,6 +424,10 @@ void DesktopHostLinux::Show() { XMapWindow(xdisplay_, xwindow_); } +void DesktopHostLinux::ToggleFullScreen() { + NOTIMPLEMENTED(); +} + gfx::Size DesktopHostLinux::GetSize() const { return size_; } diff --git a/ui/aura/desktop_host_win.cc b/ui/aura/desktop_host_win.cc index c123890..068be1a 100644 --- a/ui/aura/desktop_host_win.cc +++ b/ui/aura/desktop_host_win.cc @@ -112,7 +112,11 @@ gfx::Size DesktopHost::GetNativeDisplaySize() { GetSystemMetrics(SM_CYSCREEN)); } -DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) : desktop_(NULL) { +DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) + : desktop_(NULL), + fullscreen_(false), + saved_window_style_(0), + saved_window_ex_style_(0) { Init(NULL, bounds); SetWindowText(hwnd(), L"aura::Desktop!"); } @@ -139,6 +143,38 @@ void DesktopHostWin::Show() { ShowWindow(hwnd(), SW_SHOWNORMAL); } +void DesktopHostWin::ToggleFullScreen() { + gfx::Rect target_rect; + if (!fullscreen_) { + fullscreen_ = true; + saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); + saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); + GetWindowRect(hwnd(), &saved_window_rect_); + SetWindowLong(hwnd(), GWL_STYLE, + saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); + SetWindowLong(hwnd(), GWL_EXSTYLE, + saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | + WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi); + target_rect = mi.rcMonitor; + } else { + fullscreen_ = false; + SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_); + SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_); + target_rect = saved_window_rect_; + } + SetWindowPos(hwnd(), + NULL, + target_rect.x(), + target_rect.y(), + target_rect.width(), + target_rect.height(), + SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); +} + gfx::Size DesktopHostWin::GetSize() const { RECT r; GetClientRect(hwnd(), &r); diff --git a/ui/aura/desktop_host_win.h b/ui/aura/desktop_host_win.h index 94bc39c..201f89f 100644 --- a/ui/aura/desktop_host_win.h +++ b/ui/aura/desktop_host_win.h @@ -24,6 +24,7 @@ class DesktopHostWin : public DesktopHost, public ui::WindowImpl { virtual void SetDesktop(Desktop* desktop) OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; + virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Size GetSize() const OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; @@ -57,6 +58,11 @@ class DesktopHostWin : public DesktopHost, public ui::WindowImpl { Desktop* desktop_; + bool fullscreen_; + RECT saved_window_rect_; + DWORD saved_window_style_; + DWORD saved_window_ex_style_; + DISALLOW_COPY_AND_ASSIGN(DesktopHostWin); }; |