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

Side by Side Diff: services/ui/ws/event_dispatcher.cc

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Create anonymous namespace helper for AcceleratorTransport mojom struct. Cleanup/format codes. Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/ws/event_dispatcher.h" 5 #include "services/ui/ws/event_dispatcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "services/ui/ws/accelerator.h" 10 #include "services/ui/ws/accelerator.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 gfx::Point location = mouse_pointer_last_location_; 237 gfx::Point location = mouse_pointer_last_location_;
238 mouse_cursor_source_window_ = FindDeepestVisibleWindowForEvents(&location); 238 mouse_cursor_source_window_ = FindDeepestVisibleWindowForEvents(&location);
239 239
240 mouse_cursor_in_non_client_area_ = 240 mouse_cursor_in_non_client_area_ =
241 mouse_cursor_source_window_ 241 mouse_cursor_source_window_
242 ? IsLocationInNonclientArea(mouse_cursor_source_window_, location) 242 ? IsLocationInNonclientArea(mouse_cursor_source_window_, location)
243 : false; 243 : false;
244 } 244 }
245 } 245 }
246 246
247 bool EventDispatcher::AddAccelerator(uint32_t id, 247 bool EventDispatcher::AddAccelerators(
248 mojom::EventMatcherPtr event_matcher) { 248 std::vector<ui::mojom::AcceleratorTransportPtr> multi_accelerators) {
249 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); 249 bool all_new_accelerators = true;
250 // If an accelerator with the same id or matcher already exists, then abort. 250 for (auto iter = multi_accelerators.begin(); iter != multi_accelerators.end();
251 for (const auto& pair : accelerators_) { 251 ++iter) {
252 if (pair.first == id || accelerator->EqualEventMatcher(pair.second.get())) 252 std::unique_ptr<Accelerator> accelerator(
253 return false; 253 new Accelerator(iter->get()->id, *(iter->get()->event_matcher)));
254
255 // If an accelerator with the same id or matcher is already in the pool,
mfomitchev 2016/11/24 19:56:13 If an accelerator with the same id or matcher alre
thanhph 2016/11/29 00:08:29 Done.
256 // then try next accelerator.
257 bool accelerator_exists = false;
258 for (const auto& pair : accelerators_) {
259 if (pair.first == iter->get()->id ||
260 accelerator->EqualEventMatcher(pair.second.get())) {
261 accelerator_exists = true;
262 break;
263 }
264 }
265 if (!accelerator_exists)
mfomitchev 2016/11/24 19:56:13 Swap if/else: start with a true condition, so that
thanhph 2016/11/29 00:08:29 Done.
266 accelerators_.insert(Entry(iter->get()->id, std::move(accelerator)));
267 else
268 all_new_accelerators = false;
254 } 269 }
255 accelerators_.insert(Entry(id, std::move(accelerator))); 270 return all_new_accelerators;
256 return true;
257 } 271 }
258 272
259 void EventDispatcher::RemoveAccelerator(uint32_t id) { 273 void EventDispatcher::RemoveAccelerator(uint32_t id) {
260 auto it = accelerators_.find(id); 274 auto it = accelerators_.find(id);
261 // Clients may pass bogus ids. 275 // Clients may pass bogus ids.
262 if (it != accelerators_.end()) 276 if (it != accelerators_.end())
263 accelerators_.erase(it); 277 accelerators_.erase(it);
264 } 278 }
265 279
266 void EventDispatcher::ProcessEvent(const ui::Event& event, 280 void EventDispatcher::ProcessEvent(const ui::Event& event,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (mouse_cursor_source_window_ == window) 630 if (mouse_cursor_source_window_ == window)
617 mouse_cursor_source_window_ = nullptr; 631 mouse_cursor_source_window_ = nullptr;
618 } 632 }
619 633
620 void EventDispatcher::OnDragCursorUpdated() { 634 void EventDispatcher::OnDragCursorUpdated() {
621 delegate_->UpdateNativeCursorFromDispatcher(); 635 delegate_->UpdateNativeCursorFromDispatcher();
622 } 636 }
623 637
624 } // namespace ws 638 } // namespace ws
625 } // namespace ui 639 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698