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