Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Side by Side Diff: ash/accelerators/key_hold_detector.cc

Issue 1640503002: ash: Do not use MessageLoopForUI when not needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/display/display_animator_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "ui/aura/window_tracker.h" 11 #include "ui/aura/window_tracker.h"
12 #include "ui/aura/window_tree_host.h" 12 #include "ui/aura/window_tree_host.h"
13 #include "ui/events/event_dispatcher.h" 13 #include "ui/events/event_dispatcher.h"
14 #include "ui/events/event_processor.h" 14 #include "ui/events/event_processor.h"
15 15
16 namespace ash { 16 namespace ash {
17 namespace { 17 namespace {
18 18
19 void DispatchPressedEvent(const ui::KeyEvent& key_event, 19 void DispatchPressedEvent(const ui::KeyEvent& key_event,
20 scoped_ptr<aura::WindowTracker> tracker) { 20 scoped_ptr<aura::WindowTracker> tracker) {
21 // The target window may be gone. 21 // The target window may be gone.
22 if (tracker->windows().empty()) 22 if (tracker->windows().empty())
23 return; 23 return;
24 ui::KeyEvent event(key_event); 24 ui::KeyEvent event(key_event);
25 aura::Window* target = *(tracker->windows().begin()); 25 aura::Window* target = *(tracker->windows().begin());
26 ignore_result( 26 ignore_result(
27 target->GetHost()->event_processor()->OnEventFromSource(&event)); 27 target->GetHost()->event_processor()->OnEventFromSource(&event));
28 } 28 }
29 29
30 void PostPressedEvent(ui::KeyEvent* event) { 30 void PostPressedEvent(ui::KeyEvent* event) {
31 // Modify RELEASED event to PRESSED event. 31 // Modify RELEASED event to PRESSED event.
32 const ui::KeyEvent pressed_event( 32 const ui::KeyEvent pressed_event(
33 ui::ET_KEY_PRESSED, 33 ui::ET_KEY_PRESSED,
34 event->key_code(), 34 event->key_code(),
35 event->code(), 35 event->code(),
36 event->flags() | ui::EF_SHIFT_DOWN | ui::EF_IS_SYNTHESIZED); 36 event->flags() | ui::EF_SHIFT_DOWN | ui::EF_IS_SYNTHESIZED);
37 scoped_ptr<aura::WindowTracker> tracker(new aura::WindowTracker); 37 scoped_ptr<aura::WindowTracker> tracker(new aura::WindowTracker);
38 tracker->Add(static_cast<aura::Window*>(event->target())); 38 tracker->Add(static_cast<aura::Window*>(event->target()));
39 39
40 base::MessageLoopForUI::current()->PostTask( 40 base::ThreadTaskRunnerHandle::Get()->PostTask(
oshima 2016/01/27 22:23:53 My understanding was that we used to use MessageLo
sadrul 2016/01/27 23:44:02 ThreadTaskRunnerHandle::Get() returns the task-run
41 FROM_HERE, 41 FROM_HERE,
42 base::Bind(&DispatchPressedEvent, pressed_event, base::Passed(&tracker))); 42 base::Bind(&DispatchPressedEvent, pressed_event, base::Passed(&tracker)));
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 KeyHoldDetector::KeyHoldDetector(scoped_ptr<Delegate> delegate) 47 KeyHoldDetector::KeyHoldDetector(scoped_ptr<Delegate> delegate)
48 : state_(INITIAL), delegate_(std::move(delegate)) {} 48 : state_(INITIAL), delegate_(std::move(delegate)) {}
49 49
50 KeyHoldDetector::~KeyHoldDetector() {} 50 KeyHoldDetector::~KeyHoldDetector() {}
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (delegate_->ShouldStopEventPropagation()) 93 if (delegate_->ShouldStopEventPropagation())
94 event->StopPropagation(); 94 event->StopPropagation();
95 break; 95 break;
96 } 96 }
97 } 97 }
98 state_ = INITIAL; 98 state_ = INITIAL;
99 } 99 }
100 } 100 }
101 101
102 } // namespace ash 102 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/display/display_animator_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698