Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::AcceleratorPtr> 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 = accelerators.begin(); iter != accelerators.end(); ++iter) { |
| 251 for (const auto& pair : accelerators_) { | 251 std::unique_ptr<Accelerator> accelerator( |
| 252 if (pair.first == id || accelerator->EqualEventMatcher(pair.second.get())) | 252 new Accelerator(iter->get()->id, *(iter->get()->event_matcher))); |
|
sky
2016/12/01 22:17:04
Use MakeUnique (see threads on chomium-dev).
thanhph
2016/12/01 23:32:41
Done, thanks!
| |
| 253 return false; | 253 |
| 254 // If an accelerator with the same id or matcher already exists, skip it. | |
| 255 bool accelerator_exists = false; | |
| 256 for (const auto& pair : accelerators_) { | |
| 257 if (pair.first == iter->get()->id || | |
| 258 accelerator->EqualEventMatcher(pair.second.get())) { | |
| 259 accelerator_exists = true; | |
| 260 break; | |
| 261 } | |
| 262 } | |
| 263 if (accelerator_exists) | |
| 264 all_new_accelerators = false; | |
| 265 else | |
| 266 accelerators_.insert(Entry(iter->get()->id, std::move(accelerator))); | |
| 254 } | 267 } |
| 255 accelerators_.insert(Entry(id, std::move(accelerator))); | 268 return all_new_accelerators; |
| 256 return true; | |
| 257 } | 269 } |
| 258 | 270 |
| 259 void EventDispatcher::RemoveAccelerator(uint32_t id) { | 271 void EventDispatcher::RemoveAccelerator(uint32_t id) { |
| 260 auto it = accelerators_.find(id); | 272 auto it = accelerators_.find(id); |
| 261 // Clients may pass bogus ids. | 273 // Clients may pass bogus ids. |
| 262 if (it != accelerators_.end()) | 274 if (it != accelerators_.end()) |
| 263 accelerators_.erase(it); | 275 accelerators_.erase(it); |
| 264 } | 276 } |
| 265 | 277 |
| 266 void EventDispatcher::ProcessEvent(const ui::Event& event, | 278 void EventDispatcher::ProcessEvent(const ui::Event& event, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 if (mouse_cursor_source_window_ == window) | 628 if (mouse_cursor_source_window_ == window) |
| 617 mouse_cursor_source_window_ = nullptr; | 629 mouse_cursor_source_window_ = nullptr; |
| 618 } | 630 } |
| 619 | 631 |
| 620 void EventDispatcher::OnDragCursorUpdated() { | 632 void EventDispatcher::OnDragCursorUpdated() { |
| 621 delegate_->UpdateNativeCursorFromDispatcher(); | 633 delegate_->UpdateNativeCursorFromDispatcher(); |
| 622 } | 634 } |
| 623 | 635 |
| 624 } // namespace ws | 636 } // namespace ws |
| 625 } // namespace ui | 637 } // namespace ui |
| OLD | NEW |