| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/accelerators/key_hold_detector.h" | 5 #include "ash/accelerators/key_hold_detector.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #undef RootWindow | 9 #undef RootWindow |
| 10 #undef Status | 10 #undef Status |
| 11 | 11 |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "ui/aura/window_tracker.h" | 14 #include "ui/aura/window_tracker.h" |
| 15 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/events/event_dispatcher.h" | 16 #include "ui/events/event_dispatcher.h" |
| 17 #include "ui/events/event_processor.h" | 17 #include "ui/events/event_processor.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 void DispatchPressedEvent(const ui::KeyEvent& key_event, | 22 void DispatchPressedEvent(XEvent native_event, |
| 23 scoped_ptr<aura::WindowTracker> tracker) { | 23 scoped_ptr<aura::WindowTracker> tracker) { |
| 24 // The target window may be gone. | 24 // The target window may be gone. |
| 25 if (tracker->windows().empty()) | 25 if (tracker->windows().empty()) |
| 26 return; | 26 return; |
| 27 ui::KeyEvent event(key_event); | |
| 28 aura::Window* target = *(tracker->windows().begin()); | 27 aura::Window* target = *(tracker->windows().begin()); |
| 28 ui::KeyEvent event(&native_event); |
| 29 event.set_flags(event.flags() | ui::EF_IS_SYNTHESIZED); |
| 29 ui::EventDispatchDetails result ALLOW_UNUSED = | 30 ui::EventDispatchDetails result ALLOW_UNUSED = |
| 30 target->GetHost()->event_processor()->OnEventFromSource(&event); | 31 target->GetHost()->event_processor()->OnEventFromSource(&event); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void PostPressedEvent(ui::KeyEvent* event) { | 34 void PostPressedEvent(ui::KeyEvent* event) { |
| 34 // Modify RELEASED event to PRESSED event. | 35 // Modify RELEASED event to PRESSED event. |
| 35 const ui::KeyEvent pressed_event( | 36 XEvent xkey = *(event->native_event()); |
| 36 ui::ET_KEY_PRESSED, | 37 xkey.xkey.type = KeyPress; |
| 37 event->key_code(), | 38 xkey.xkey.state |= ShiftMask; |
| 38 event->code(), | |
| 39 event->flags() | ui::EF_SHIFT_DOWN | ui::EF_IS_SYNTHESIZED); | |
| 40 scoped_ptr<aura::WindowTracker> tracker(new aura::WindowTracker); | 39 scoped_ptr<aura::WindowTracker> tracker(new aura::WindowTracker); |
| 41 tracker->Add(static_cast<aura::Window*>(event->target())); | 40 tracker->Add(static_cast<aura::Window*>(event->target())); |
| 42 | 41 |
| 43 base::MessageLoopForUI::current()->PostTask( | 42 base::MessageLoopForUI::current()->PostTask( |
| 44 FROM_HERE, | 43 FROM_HERE, |
| 45 base::Bind(&DispatchPressedEvent, pressed_event, base::Passed(&tracker))); | 44 base::Bind(&DispatchPressedEvent, xkey, base::Passed(&tracker))); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 KeyHoldDetector::KeyHoldDetector(scoped_ptr<Delegate> delegate) | 49 KeyHoldDetector::KeyHoldDetector(scoped_ptr<Delegate> delegate) |
| 51 : state_(INITIAL), | 50 : state_(INITIAL), |
| 52 delegate_(delegate.Pass()) {} | 51 delegate_(delegate.Pass()) {} |
| 53 | 52 |
| 54 KeyHoldDetector::~KeyHoldDetector() {} | 53 KeyHoldDetector::~KeyHoldDetector() {} |
| 55 | 54 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 delegate_->OnKeyUnhold(event); | 90 delegate_->OnKeyUnhold(event); |
| 92 event->StopPropagation(); | 91 event->StopPropagation(); |
| 93 break; | 92 break; |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 state_ = INITIAL; | 95 state_ = INITIAL; |
| 97 } | 96 } |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace ash | 99 } // namespace ash |
| OLD | NEW |