summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 21:51:43 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 21:51:43 +0000
commit593ddfa5b36b3fcea4ba20b054f00338adb4caf3 (patch)
treeb31eafeb93112c5e9eaa183e54a0051984462ba8
parent0bc2efd12616518e3952be87a078d53ab5adfca5 (diff)
downloadchromium_src-593ddfa5b36b3fcea4ba20b054f00338adb4caf3.zip
chromium_src-593ddfa5b36b3fcea4ba20b054f00338adb4caf3.tar.gz
chromium_src-593ddfa5b36b3fcea4ba20b054f00338adb4caf3.tar.bz2
aura: Add transform support to Desktop.
For painting, the transform gets applied to the root layer of the compositor. For testing purposes, ctrl+Home is set to rotate the desktop (this can be made better when there's hotkey support). BUG=100600 TEST=none Review URL: http://codereview.chromium.org/8329019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106594 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/desktop.cc76
-rw-r--r--ui/aura/desktop.h13
-rw-r--r--ui/aura/desktop_host_linux.cc16
-rw-r--r--ui/aura/desktop_host_win.cc5
-rw-r--r--ui/aura/event.cc8
-rw-r--r--ui/aura/event.h6
-rw-r--r--ui/aura/test/event_generator.cc34
-rw-r--r--ui/aura/test/event_generator.h2
-rw-r--r--ui/aura/window.cc4
-rw-r--r--ui/aura/window.h3
-rw-r--r--ui/aura/window_unittest.cc78
11 files changed, 190 insertions, 55 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index d48f0d0..db2aaa6 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -89,7 +89,9 @@ void Desktop::SetHostSize(const gfx::Size& size) {
}
gfx::Size Desktop::GetHostSize() const {
- return host_->GetSize();
+ gfx::Rect rect(host_->GetSize());
+ layer()->transform().TransformRect(&rect);
+ return rect.size();
}
void Desktop::SetCursor(gfx::NativeCursor cursor) {
@@ -105,16 +107,18 @@ void Desktop::Draw() {
compositor_->Draw(false);
}
-bool Desktop::OnMouseEvent(const MouseEvent& event) {
- last_mouse_location_ = event.location();
+bool Desktop::DispatchMouseEvent(MouseEvent* event) {
+ event->UpdateForTransform(layer()->transform());
+
+ last_mouse_location_ = event->location();
Window* target =
mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_;
if (!target)
- target = GetEventHandlerForPoint(event.location());
- switch (event.type()) {
+ target = GetEventHandlerForPoint(event->location());
+ switch (event->type()) {
case ui::ET_MOUSE_MOVED:
- HandleMouseMoved(event, target);
+ HandleMouseMoved(*event, target);
break;
case ui::ET_MOUSE_PRESSED:
if (!mouse_pressed_handler_)
@@ -127,28 +131,57 @@ bool Desktop::OnMouseEvent(const MouseEvent& event) {
break;
}
if (target && target->delegate()) {
- MouseEvent translated_event(event, this, target);
+ MouseEvent translated_event(*event, this, target);
return target->OnMouseEvent(&translated_event);
}
return false;
}
-bool Desktop::OnKeyEvent(const KeyEvent& event) {
+bool Desktop::DispatchKeyEvent(KeyEvent* event) {
+#if !defined(NDEBUG)
+ // Press Home key to rotate the screen. Primarily used for testing.
+ if (event->type() == ui::ET_KEY_PRESSED &&
+ (event->flags() & ui::EF_CONTROL_DOWN) &&
+ event->key_code() == ui::VKEY_HOME) {
+ ui::Transform transform;
+ static int count = 0;
+ gfx::Size size = host_->GetSize();
+ switch (count) {
+ case 0:
+ transform.ConcatRotate(-90.0f);
+ transform.ConcatTranslate(0, size.height());
+ break;
+ case 1:
+ transform.ConcatRotate(90.0f);
+ transform.ConcatTranslate(size.width(), 0);
+ break;
+ case 2:
+ transform.ConcatRotate(180.0f);
+ transform.ConcatTranslate(size.width(), size.height());
+ break;
+ }
+ SetTransform(transform);
+ count = (count + 1) % 4;
+ return true;
+ }
+#endif
+
if (focused_window_) {
- KeyEvent translated_event(event);
+ KeyEvent translated_event(*event);
return focused_window_->OnKeyEvent(&translated_event);
}
return false;
}
-bool Desktop::OnTouchEvent(const TouchEvent& event) {
+bool Desktop::DispatchTouchEvent(TouchEvent* event) {
+ event->UpdateForTransform(layer()->transform());
bool handled = false;
Window* target =
touch_event_handler_ ? touch_event_handler_ : capture_window_;
if (!target)
- target = GetEventHandlerForPoint(event.location());
+ target = GetEventHandlerForPoint(event->location());
if (target) {
- TouchEvent translated_event(event, this, target);
+ TouchEvent translated_event(*event, this, target);
ui::TouchStatus status = target->OnTouchEvent(&translated_event);
if (status == ui::TOUCH_STATUS_START)
touch_event_handler_ = target;
@@ -161,10 +194,16 @@ bool Desktop::OnTouchEvent(const TouchEvent& event) {
}
void Desktop::OnHostResized(const gfx::Size& size) {
- gfx::Rect bounds(0, 0, size.width(), size.height());
+ // The compositor should have the same size as the native desktop host.
compositor_->WidgetSizeChanged(size);
- SetBounds(bounds);
- FOR_EACH_OBSERVER(DesktopObserver, observers_, OnDesktopResized(size));
+
+ // The layer, and all the observers should be notified of the
+ // transformed size of the desktop.
+ gfx::Rect bounds(size);
+ layer()->transform().TransformRect(&bounds);
+ SetBounds(gfx::Rect(bounds.size()));
+ FOR_EACH_OBSERVER(DesktopObserver, observers_,
+ OnDesktopResized(bounds.size()));
}
void Desktop::SetActiveWindow(Window* window, Window* to_focus) {
@@ -304,6 +343,13 @@ void Desktop::ScheduleDraw() {
}
}
+void Desktop::SetTransform(const ui::Transform& transform) {
+ Window::SetTransform(transform);
+
+ // The transform can effect the size of the desktop.
+ OnHostResized(host_->GetSize());
+}
+
bool Desktop::CanFocus() const {
return IsVisible();
}
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index 16a0244..e6c12b3 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -24,6 +24,10 @@ namespace gfx {
class Size;
}
+namespace ui {
+class Transform;
+}
+
namespace aura {
class DesktopDelegate;
@@ -79,13 +83,13 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
void Draw();
// Handles a mouse event. Returns true if handled.
- bool OnMouseEvent(const MouseEvent& event);
+ bool DispatchMouseEvent(MouseEvent* event);
// Handles a key event. Returns true if handled.
- bool OnKeyEvent(const KeyEvent& event);
+ bool DispatchKeyEvent(KeyEvent* event);
// Handles a touch event. Returns true if handled.
- bool OnTouchEvent(const TouchEvent& event);
+ bool DispatchTouchEvent(TouchEvent* event);
// Called when the host changes size.
void OnHostResized(const gfx::Size& size);
@@ -124,6 +128,9 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
// If |window| has mouse capture, the current capture window is set to NULL.
void ReleaseCapture(Window* window);
+ // Overridden from Window:
+ virtual void SetTransform(const ui::Transform& transform) OVERRIDE;
+
private:
// Called whenever the mouse moves, tracks the current |mouse_moved_handler_|,
// sending exited and entered events as its value changes.
diff --git a/ui/aura/desktop_host_linux.cc b/ui/aura/desktop_host_linux.cc
index b321657..1eff7ed 100644
--- a/ui/aura/desktop_host_linux.cc
+++ b/ui/aura/desktop_host_linux.cc
@@ -19,6 +19,7 @@
#include "ui/aura/event.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/x/x11_util.h"
+#include "ui/gfx/compositor/layer.h"
#include <X11/cursorfont.h>
#include <X11/extensions/XInput2.h>
@@ -251,20 +252,20 @@ base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
break;
case KeyPress: {
KeyEvent keydown_event(xev, false);
- handled = desktop_->OnKeyEvent(keydown_event);
+ handled = desktop_->DispatchKeyEvent(&keydown_event);
KeyEvent char_event(xev, true);
- handled |= desktop_->OnKeyEvent(char_event);
+ handled |= desktop_->DispatchKeyEvent(&char_event);
break;
}
case KeyRelease: {
KeyEvent keyup_event(xev, false);
- handled = desktop_->OnKeyEvent(keyup_event);
+ handled = desktop_->DispatchKeyEvent(&keyup_event);
break;
}
case ButtonPress:
case ButtonRelease: {
MouseEvent mouseev(xev);
- handled = desktop_->OnMouseEvent(mouseev);
+ handled = desktop_->DispatchMouseEvent(&mouseev);
break;
}
case MotionNotify: {
@@ -284,8 +285,9 @@ base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
break;
}
}
+
MouseEvent mouseev(xev);
- handled = desktop_->OnMouseEvent(mouseev);
+ handled = desktop_->DispatchMouseEvent(&mouseev);
break;
}
case ConfigureNotify: {
@@ -325,7 +327,7 @@ base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
case ui::ET_TOUCH_RELEASED:
case ui::ET_TOUCH_MOVED: {
TouchEvent touchev(xev);
- handled = desktop_->OnTouchEvent(touchev);
+ handled = desktop_->DispatchTouchEvent(&touchev);
break;
}
case ui::ET_MOUSE_PRESSED:
@@ -336,7 +338,7 @@ base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
case ui::ET_MOUSE_ENTERED:
case ui::ET_MOUSE_EXITED: {
MouseEvent mouseev(xev);
- handled = desktop_->OnMouseEvent(mouseev);
+ handled = desktop_->DispatchMouseEvent(&mouseev);
break;
}
case ui::ET_UNKNOWN:
diff --git a/ui/aura/desktop_host_win.cc b/ui/aura/desktop_host_win.cc
index 0c8f234..27fcb52 100644
--- a/ui/aura/desktop_host_win.cc
+++ b/ui/aura/desktop_host_win.cc
@@ -177,7 +177,8 @@ LRESULT DesktopHostWin::OnKeyEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param };
- SetMsgHandled(desktop_->OnKeyEvent(KeyEvent(msg, message == WM_CHAR)));
+ KeyEvent keyev(msg, message == WM_CHAR);
+ SetMsgHandled(desktop_->DispatchKeyEvent(&keyev));
return 0;
}
@@ -189,7 +190,7 @@ LRESULT DesktopHostWin::OnMouseRange(UINT message,
MouseEvent event(msg);
bool handled = false;
if (!(event.flags() & ui::EF_IS_NON_CLIENT))
- handled = desktop_->OnMouseEvent(event);
+ handled = desktop_->DispatchMouseEvent(&event);
SetMsgHandled(handled);
return 0;
}
diff --git a/ui/aura/event.cc b/ui/aura/event.cc
index 08940eb..4034c09 100644
--- a/ui/aura/event.cc
+++ b/ui/aura/event.cc
@@ -5,6 +5,8 @@
#include "ui/aura/event.h"
#include "ui/aura/window.h"
+#include "ui/gfx/point3.h"
+#include "ui/gfx/transform.h"
namespace aura {
@@ -62,6 +64,12 @@ LocatedEvent::LocatedEvent(ui::EventType type,
location_(location) {
}
+void LocatedEvent::UpdateForTransform(const ui::Transform& transform) {
+ gfx::Point3f p(location_);
+ transform.TransformPointReverse(p);
+ location_ = p.AsPoint();
+}
+
MouseEvent::MouseEvent(const base::NativeEvent& native_event)
: LocatedEvent(native_event) {
}
diff --git a/ui/aura/event.h b/ui/aura/event.h
index 9673d0f..2691d65 100644
--- a/ui/aura/event.h
+++ b/ui/aura/event.h
@@ -14,6 +14,10 @@
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h"
+namespace ui {
+class Transform;
+}
+
namespace aura {
class Window;
@@ -50,6 +54,8 @@ class AURA_EXPORT LocatedEvent : public Event {
int y() const { return location_.y(); }
gfx::Point location() const { return location_; }
+ void UpdateForTransform(const ui::Transform& transform);
+
protected:
explicit LocatedEvent(const base::NativeEvent& native_event);
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc
index c90343c..e2e3673 100644
--- a/ui/aura/test/event_generator.cc
+++ b/ui/aura/test/event_generator.cc
@@ -45,26 +45,34 @@ void EventGenerator::ClickLeftButton() {
void EventGenerator::PressLeftButton() {
if ((flags_ & ui::EF_LEFT_BUTTON_DOWN) == 0) {
flags_ |= ui::EF_LEFT_BUTTON_DOWN;
- Dispatch(MouseEvent(ui::ET_MOUSE_PRESSED, current_location_, flags_));
+ MouseEvent mouseev(ui::ET_MOUSE_PRESSED, current_location_, flags_);
+ Dispatch(mouseev);
}
}
void EventGenerator::ReleaseLeftButton() {
if (flags_ & ui::EF_LEFT_BUTTON_DOWN) {
flags_ ^= ui::EF_LEFT_BUTTON_DOWN;
- Dispatch(MouseEvent(ui::ET_MOUSE_RELEASED, current_location_, 0));
+ MouseEvent mouseev(ui::ET_MOUSE_RELEASED, current_location_, 0);
+ Dispatch(mouseev);
}
}
void EventGenerator::MoveMouseTo(const gfx::Point& point) {
if (flags_ & ui::EF_LEFT_BUTTON_DOWN ) {
- Dispatch(MouseEvent(
- ui::ET_MOUSE_DRAGGED, current_location_.Middle(point), flags_));
- Dispatch(MouseEvent(ui::ET_MOUSE_DRAGGED, point, flags_));
+ MouseEvent middle(
+ ui::ET_MOUSE_DRAGGED, current_location_.Middle(point), flags_);
+ Dispatch(middle);
+
+ MouseEvent mouseev(ui::ET_MOUSE_DRAGGED, point, flags_);
+ Dispatch(mouseev);
} else {
- Dispatch(MouseEvent(
- ui::ET_MOUSE_MOVED, current_location_.Middle(point), flags_));
- Dispatch(MouseEvent(ui::ET_MOUSE_MOVED, point, flags_));
+ MouseEvent middle(
+ ui::ET_MOUSE_MOVED, current_location_.Middle(point), flags_);
+ Dispatch(middle);
+
+ MouseEvent mouseev(ui::ET_MOUSE_MOVED, point, flags_);
+ Dispatch(mouseev);
}
current_location_ = point;
}
@@ -75,12 +83,12 @@ void EventGenerator::DragMouseTo(const gfx::Point& point) {
ReleaseLeftButton();
}
-void EventGenerator::Dispatch(const Event& event) {
+void EventGenerator::Dispatch(Event& event) {
switch (event.type()) {
case ui::ET_KEY_PRESSED:
case ui::ET_KEY_RELEASED:
- aura::Desktop::GetInstance()->OnKeyEvent(
- *static_cast<const KeyEvent*>(&event));
+ aura::Desktop::GetInstance()->DispatchKeyEvent(
+ static_cast<KeyEvent*>(&event));
break;
case ui::ET_MOUSE_PRESSED:
case ui::ET_MOUSE_DRAGGED:
@@ -89,8 +97,8 @@ void EventGenerator::Dispatch(const Event& event) {
case ui::ET_MOUSE_ENTERED:
case ui::ET_MOUSE_EXITED:
case ui::ET_MOUSEWHEEL:
- aura::Desktop::GetInstance()->OnMouseEvent(
- *static_cast<const MouseEvent*>(&event));
+ aura::Desktop::GetInstance()->DispatchMouseEvent(
+ static_cast<MouseEvent*>(&event));
break;
default:
NOTIMPLEMENTED();
diff --git a/ui/aura/test/event_generator.h b/ui/aura/test/event_generator.h
index afafd4e..f375f9d 100644
--- a/ui/aura/test/event_generator.h
+++ b/ui/aura/test/event_generator.h
@@ -68,7 +68,7 @@ class EventGenerator {
private:
// Dispatch the |event| to the Desktop.
- void Dispatch(const Event& event);
+ void Dispatch(Event& event);
int flags_;
gfx::Point current_location_;
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index e3945e1..cd60b6c 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -131,6 +131,10 @@ const ToplevelWindowContainer* Window::AsToplevelWindowContainer() const {
return NULL;
}
+void Window::SetTransform(const ui::Transform& transform) {
+ layer()->SetTransform(transform);
+}
+
void Window::SetLayoutManager(LayoutManager* layout_manager) {
layout_manager_.reset(layout_manager);
}
diff --git a/ui/aura/window.h b/ui/aura/window.h
index a2b9617..0eb8d98 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -25,6 +25,7 @@ namespace ui {
class Animation;
class Compositor;
class Layer;
+class Transform;
}
namespace aura {
@@ -115,6 +116,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
virtual ToplevelWindowContainer* AsToplevelWindowContainer();
virtual const ToplevelWindowContainer* AsToplevelWindowContainer() const;
+ virtual void SetTransform(const ui::Transform& transform);
+
// Assigns a LayoutManager to size and place child windows.
// The Window takes ownership of the LayoutManager.
void SetLayoutManager(LayoutManager* layout_manager);
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index a73d85e..94233bb 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -310,25 +310,27 @@ TEST_F(WindowTest, Focus) {
// Click on a sub-window (w121) to focus it.
gfx::Point click_point = w121->bounds().CenterPoint();
Window::ConvertPointToWindow(w121->parent(), desktop, &click_point);
- desktop->OnMouseEvent(
- MouseEvent(ui::ET_MOUSE_PRESSED, click_point, ui::EF_LEFT_BUTTON_DOWN));
+ MouseEvent mouse(ui::ET_MOUSE_PRESSED, click_point, ui::EF_LEFT_BUTTON_DOWN);
+ desktop->DispatchMouseEvent(&mouse);
internal::FocusManager* focus_manager = w121->GetFocusManager();
EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow());
// The key press should be sent to the focused sub-window.
- desktop->OnKeyEvent(KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, 0));
+ KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0);
+ desktop->DispatchKeyEvent(&keyev);
EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
// Touch on a sub-window (w122) to focus it.
click_point = w122->bounds().CenterPoint();
Window::ConvertPointToWindow(w122->parent(), desktop, &click_point);
- desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, click_point, 0));
+ TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0);
+ desktop->DispatchTouchEvent(&touchev);
focus_manager = w122->GetFocusManager();
EXPECT_EQ(w122.get(), focus_manager->GetFocusedWindow());
// The key press should be sent to the focused sub-window.
- desktop->OnKeyEvent(KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_F, 0));
- EXPECT_EQ(ui::VKEY_F, w122delegate->last_key_code());
+ desktop->DispatchKeyEvent(&keyev);
+ EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
}
// Various destruction assertions.
@@ -394,8 +396,8 @@ TEST_F(WindowTest, CaptureTests) {
EXPECT_EQ(2, delegate.mouse_event_count());
delegate.set_mouse_event_count(0);
- desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50),
- 0));
+ TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0);
+ desktop->DispatchTouchEvent(&touchev);
EXPECT_EQ(1, delegate.touch_event_count());
delegate.set_touch_event_count(0);
@@ -406,8 +408,7 @@ TEST_F(WindowTest, CaptureTests) {
generator.PressLeftButton();
EXPECT_EQ(0, delegate.mouse_event_count());
- desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50),
- 0));
+ desktop->DispatchTouchEvent(&touchev);
EXPECT_EQ(0, delegate.touch_event_count());
}
@@ -474,7 +475,8 @@ TEST_F(WindowTest, MouseEnterExit) {
gfx::Point move_point = w1->bounds().CenterPoint();
Window::ConvertPointToWindow(w1->parent(), desktop, &move_point);
- desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_MOVED, move_point, 0));
+ MouseEvent mouseev1(ui::ET_MOUSE_MOVED, move_point, 0);
+ desktop->DispatchMouseEvent(&mouseev1);
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
@@ -483,7 +485,8 @@ TEST_F(WindowTest, MouseEnterExit) {
move_point = w2->bounds().CenterPoint();
Window::ConvertPointToWindow(w2->parent(), desktop, &move_point);
- desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_MOVED, move_point, 0));
+ MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0);
+ desktop->DispatchMouseEvent(&mouseev2);
EXPECT_TRUE(d1.entered());
EXPECT_TRUE(d1.exited());
@@ -627,7 +630,8 @@ TEST_F(WindowTest, ActivateOnTouch) {
// Touch window2.
gfx::Point press_point = w2->bounds().CenterPoint();
Window::ConvertPointToWindow(w2->parent(), desktop, &press_point);
- desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, press_point, 0));
+ TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0);
+ desktop->DispatchTouchEvent(&touchev1);
// Window2 should have become active.
EXPECT_EQ(w2.get(), desktop->active_window());
@@ -643,7 +647,8 @@ TEST_F(WindowTest, ActivateOnTouch) {
press_point = w1->bounds().CenterPoint();
Window::ConvertPointToWindow(w1->parent(), desktop, &press_point);
d1.set_activate(false);
- desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, press_point, 0));
+ TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 0);
+ desktop->DispatchTouchEvent(&touchev2);
// Window2 should still be active and focused.
EXPECT_EQ(w2.get(), desktop->active_window());
@@ -938,6 +943,51 @@ TEST_F(WindowTest, IsOrContainsFullscreenWindow) {
EXPECT_FALSE(root->IsOrContainsFullscreenWindow());
}
+#if !defined(OS_WIN)
+// Tests transformation on the desktop.
+TEST_F(WindowTest, Transform) {
+ Desktop* desktop = Desktop::GetInstance();
+ gfx::Size size(200, 300);
+ desktop->SetHostSize(size);
+ desktop->ShowDesktop();
+
+ EXPECT_EQ(gfx::Rect(size), gfx::Rect(desktop->GetHostSize()));
+ EXPECT_EQ(gfx::Rect(size),
+ gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()));
+
+ // Rotate it clock-wise 90 degrees.
+ ui::Transform transform;
+ transform.SetRotate(90.0f);
+ transform.ConcatTranslate(size.width(), 0);
+ desktop->SetTransform(transform);
+
+ // The size should be the transformed size.
+ EXPECT_EQ(gfx::Rect(0, 0, 300, 200), gfx::Rect(desktop->GetHostSize()));
+ EXPECT_EQ(gfx::Rect(0, 0, 300, 200), desktop->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 300, 200),
+ gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()));
+
+ ActivateWindowDelegate d1;
+ scoped_ptr<Window> w1(
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(0, 10, 50, 50), NULL));
+ w1->Show();
+
+ MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
+ gfx::Point(195, 5), ui::EF_LEFT_BUTTON_DOWN);
+ desktop->DispatchMouseEvent(&mouseev1);
+ EXPECT_FALSE(w1->GetFocusManager()->GetFocusedWindow());
+ MouseEvent mouseup(ui::ET_MOUSE_RELEASED,
+ gfx::Point(195, 5), ui::EF_LEFT_BUTTON_DOWN);
+ desktop->DispatchMouseEvent(&mouseup);
+
+ MouseEvent mouseev2(ui::ET_MOUSE_PRESSED,
+ gfx::Point(185, 5), ui::EF_LEFT_BUTTON_DOWN);
+ desktop->DispatchMouseEvent(&mouseev2);
+ EXPECT_EQ(w1.get(), desktop->active_window());
+ EXPECT_EQ(w1.get(), w1->GetFocusManager()->GetFocusedWindow());
+}
+#endif
+
class ToplevelWindowTest : public WindowTest {
public:
ToplevelWindowTest() {}