| 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 "ui/ozone/platform/dri/dri_window_manager.h" | 5 #include "ui/ozone/platform/dri/dri_window_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/ozone/platform/dri/dri_cursor.h" | 8 #include "ui/ozone/platform/dri/dri_cursor.h" |
| 9 #include "ui/ozone/platform/dri/dri_window.h" | 9 #include "ui/ozone/platform/dri/dri_window.h" |
| 10 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 gfx::PointF GetDefaultCursorLocation(DriWindow* window) { | 15 gfx::PointF GetDefaultCursorLocation(DriWindow* window) { |
| 16 return gfx::PointF(window->GetBounds().width() / 2, | 16 return gfx::PointF(window->GetBounds().width() / 2, |
| 17 window->GetBounds().height() / 2); | 17 window->GetBounds().height() / 2); |
| 18 } | 18 } |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 DriWindowManager::DriWindowManager(HardwareCursorDelegate* cursor_delegate) | 22 DriWindowManager::DriWindowManager(HardwareCursorDelegate* cursor_delegate) |
| 23 : last_allocated_widget_(0), cursor_(new DriCursor(cursor_delegate, this)) { | 23 : last_allocated_widget_(0), |
| 24 cursor_(new DriCursor(cursor_delegate, this)), |
| 25 mouse_events_grabber_(gfx::kNullAcceleratedWidget) { |
| 24 } | 26 } |
| 25 | 27 |
| 26 DriWindowManager::~DriWindowManager() { | 28 DriWindowManager::~DriWindowManager() { |
| 27 } | 29 } |
| 28 | 30 |
| 29 gfx::AcceleratedWidget DriWindowManager::NextAcceleratedWidget() { | 31 gfx::AcceleratedWidget DriWindowManager::NextAcceleratedWidget() { |
| 30 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an | 32 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an |
| 31 // invalid widget. | 33 // invalid widget. |
| 32 return ++last_allocated_widget_; | 34 return ++last_allocated_widget_; |
| 33 } | 35 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 | 46 |
| 45 void DriWindowManager::RemoveWindow(gfx::AcceleratedWidget widget) { | 47 void DriWindowManager::RemoveWindow(gfx::AcceleratedWidget widget) { |
| 46 WidgetToWindowMap::iterator it = window_map_.find(widget); | 48 WidgetToWindowMap::iterator it = window_map_.find(widget); |
| 47 if (it != window_map_.end()) | 49 if (it != window_map_.end()) |
| 48 window_map_.erase(it); | 50 window_map_.erase(it); |
| 49 else | 51 else |
| 50 NOTREACHED() << "Attempting to remove non-existing window " << widget; | 52 NOTREACHED() << "Attempting to remove non-existing window " << widget; |
| 51 | 53 |
| 52 if (cursor_->GetCursorWindow() == widget) | 54 if (cursor_->GetCursorWindow() == widget) |
| 53 ResetCursorLocation(); | 55 ResetCursorLocation(); |
| 56 if (mouse_events_grabber_ == widget) |
| 57 mouse_events_grabber_ = gfx::kNullAcceleratedWidget; |
| 54 } | 58 } |
| 55 | 59 |
| 56 DriWindow* DriWindowManager::GetWindow(gfx::AcceleratedWidget widget) { | 60 DriWindow* DriWindowManager::GetWindow(gfx::AcceleratedWidget widget) { |
| 57 WidgetToWindowMap::iterator it = window_map_.find(widget); | 61 WidgetToWindowMap::iterator it = window_map_.find(widget); |
| 58 if (it != window_map_.end()) | 62 if (it != window_map_.end()) |
| 59 return it->second; | 63 return it->second; |
| 60 | 64 |
| 61 NOTREACHED() << "Attempting to get non-existing window " << widget; | 65 NOTREACHED() << "Attempting to get non-existing window " << widget; |
| 62 return NULL; | 66 return NULL; |
| 63 } | 67 } |
| 64 | 68 |
| 65 void DriWindowManager::ResetCursorLocation() { | 69 void DriWindowManager::ResetCursorLocation() { |
| 66 gfx::AcceleratedWidget cursor_widget = gfx::kNullAcceleratedWidget; | 70 gfx::AcceleratedWidget cursor_widget = gfx::kNullAcceleratedWidget; |
| 67 gfx::PointF location; | 71 gfx::PointF location; |
| 68 if (!window_map_.empty()) { | 72 if (!window_map_.empty()) { |
| 69 WidgetToWindowMap::iterator it = window_map_.begin(); | 73 WidgetToWindowMap::iterator it = window_map_.begin(); |
| 70 cursor_widget = it->first; | 74 cursor_widget = it->first; |
| 71 location = GetDefaultCursorLocation(it->second); | 75 location = GetDefaultCursorLocation(it->second); |
| 72 } | 76 } |
| 73 | 77 |
| 74 cursor_->MoveCursorTo(cursor_widget, location); | 78 cursor_->MoveCursorTo(cursor_widget, location); |
| 75 } | 79 } |
| 76 | 80 |
| 81 void DriWindowManager::GrabMouseEvents(gfx::AcceleratedWidget widget) { |
| 82 if (mouse_events_grabber_ == gfx::kNullAcceleratedWidget) |
| 83 mouse_events_grabber_ = widget; |
| 84 } |
| 85 |
| 86 void DriWindowManager::UngrabMouseEvents(gfx::AcceleratedWidget widget) { |
| 87 if (mouse_events_grabber_ == widget) |
| 88 mouse_events_grabber_ = gfx::kNullAcceleratedWidget; |
| 89 } |
| 90 |
| 77 } // namespace ui | 91 } // namespace ui |
| OLD | NEW |