| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/native_viewport/native_viewport.h" | 5 #include "mojo/services/native_viewport/native_viewport.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 12 #include "ui/events/event_utils.h" | 13 #include "ui/events/event_utils.h" |
| 13 #include "ui/events/platform/platform_event_dispatcher.h" | 14 #include "ui/events/platform/platform_event_dispatcher.h" |
| 14 #include "ui/events/platform/platform_event_source.h" | 15 #include "ui/events/platform/platform_event_source.h" |
| 15 #include "ui/events/platform/x11/x11_event_source.h" | 16 #include "ui/events/platform/x11/x11_event_source.h" |
| 16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/x/x11_types.h" | 18 #include "ui/gfx/x/x11_types.h" |
| 18 | 19 |
| 19 namespace mojo { | 20 namespace mojo { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // ui::PlatformEventDispatcher: | 127 // ui::PlatformEventDispatcher: |
| 127 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | 128 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 128 // TODO(aa): This is going to have to be thought through more carefully. | 129 // TODO(aa): This is going to have to be thought through more carefully. |
| 129 // Which events are appropriate to pass to clients? | 130 // Which events are appropriate to pass to clients? |
| 130 switch (event->type) { | 131 switch (event->type) { |
| 131 case KeyPress: | 132 case KeyPress: |
| 132 case KeyRelease: | 133 case KeyRelease: |
| 133 case ButtonPress: | 134 case ButtonPress: |
| 134 case ButtonRelease: | 135 case ButtonRelease: |
| 135 case MotionNotify: | 136 case MotionNotify: |
| 137 case ConfigureNotify: |
| 136 return true; | 138 return true; |
| 137 case ClientMessage: | 139 case ClientMessage: |
| 138 return event->xclient.message_type == atom_wm_protocols_; | 140 return event->xclient.message_type == atom_wm_protocols_; |
| 139 default: | 141 default: |
| 140 return false; | 142 return false; |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 | 145 |
| 144 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | 146 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 145 if (event->type == ClientMessage) { | 147 if (event->type == ClientMessage) { |
| 146 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); | 148 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); |
| 147 if (protocol == atom_wm_delete_window_) | 149 if (protocol == atom_wm_delete_window_) |
| 148 delegate_->OnDestroyed(); | 150 delegate_->OnDestroyed(); |
| 149 } else if (event->type == KeyPress || event->type == KeyRelease) { | 151 } else if (event->type == KeyPress || event->type == KeyRelease) { |
| 150 ui::KeyEvent key_event(event, false); | 152 ui::KeyEvent key_event(event, false); |
| 151 delegate_->OnEvent(&key_event); | 153 delegate_->OnEvent(&key_event); |
| 152 } else if (event->type == ButtonPress || event->type == ButtonRelease || | 154 } else if (event->type == ButtonPress || event->type == ButtonRelease || |
| 153 event->type == MotionNotify) { | 155 event->type == MotionNotify) { |
| 154 ui::EventType event_type = ui::EventTypeFromNative(event); | 156 ui::EventType event_type = ui::EventTypeFromNative(event); |
| 155 if (event_type == ui::ET_MOUSEWHEEL) { | 157 if (event_type == ui::ET_MOUSEWHEEL) { |
| 156 ui::MouseWheelEvent mouse_event(event); | 158 ui::MouseWheelEvent mouse_event(event); |
| 157 delegate_->OnEvent(&mouse_event); | 159 delegate_->OnEvent(&mouse_event); |
| 158 } else { | 160 } else { |
| 159 ui::MouseEvent mouse_event(event); | 161 ui::MouseEvent mouse_event(event); |
| 160 delegate_->OnEvent(&mouse_event); | 162 delegate_->OnEvent(&mouse_event); |
| 161 } | 163 } |
| 164 } else if (event->type == ConfigureNotify) { |
| 165 bounds_ = gfx::Rect(event->xconfigure.width, event->xconfigure.height); |
| 166 delegate_->OnBoundsChanged(bounds_); |
| 162 } | 167 } |
| 163 return ui::POST_DISPATCH_NONE; | 168 return ui::POST_DISPATCH_NONE; |
| 164 } | 169 } |
| 165 | 170 |
| 166 scoped_ptr<ui::PlatformEventSource> event_source_; | 171 scoped_ptr<ui::PlatformEventSource> event_source_; |
| 167 NativeViewportDelegate* delegate_; | 172 NativeViewportDelegate* delegate_; |
| 168 gfx::Rect bounds_; | 173 gfx::Rect bounds_; |
| 169 XID window_; | 174 XID window_; |
| 170 Atom atom_wm_protocols_; | 175 Atom atom_wm_protocols_; |
| 171 Atom atom_wm_delete_window_; | 176 Atom atom_wm_delete_window_; |
| 172 | 177 |
| 173 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); | 178 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); |
| 174 }; | 179 }; |
| 175 | 180 |
| 176 // static | 181 // static |
| 177 scoped_ptr<NativeViewport> NativeViewport::Create( | 182 scoped_ptr<NativeViewport> NativeViewport::Create( |
| 178 shell::Context* context, | 183 shell::Context* context, |
| 179 NativeViewportDelegate* delegate) { | 184 NativeViewportDelegate* delegate) { |
| 180 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); | 185 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); |
| 181 } | 186 } |
| 182 | 187 |
| 183 } // namespace services | 188 } // namespace services |
| 184 } // namespace mojo | 189 } // namespace mojo |
| OLD | NEW |