| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/ozone/platform/dri/dri_window_manager.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/ozone/platform/dri/dri_cursor.h" | |
| 9 #include "ui/ozone/platform/dri/dri_window.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 gfx::PointF GetDefaultCursorLocation(DriWindow* window) { | |
| 16 return gfx::PointF(window->GetBounds().width() / 2, | |
| 17 window->GetBounds().height() / 2); | |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 DriWindowManager::DriWindowManager(HardwareCursorDelegate* cursor_delegate) | |
| 23 : last_allocated_widget_(0), cursor_(new DriCursor(cursor_delegate, this)) { | |
| 24 } | |
| 25 | |
| 26 DriWindowManager::~DriWindowManager() { | |
| 27 } | |
| 28 | |
| 29 gfx::AcceleratedWidget DriWindowManager::NextAcceleratedWidget() { | |
| 30 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an | |
| 31 // invalid widget. | |
| 32 return ++last_allocated_widget_; | |
| 33 } | |
| 34 | |
| 35 void DriWindowManager::AddWindow(gfx::AcceleratedWidget widget, | |
| 36 DriWindow* window) { | |
| 37 std::pair<WidgetToWindowMap::iterator, bool> result = window_map_.insert( | |
| 38 std::pair<gfx::AcceleratedWidget, DriWindow*>(widget, window)); | |
| 39 DCHECK(result.second) << "Window for " << widget << " already added."; | |
| 40 | |
| 41 if (cursor_->GetCursorWindow() == gfx::kNullAcceleratedWidget) | |
| 42 ResetCursorLocation(); | |
| 43 } | |
| 44 | |
| 45 void DriWindowManager::RemoveWindow(gfx::AcceleratedWidget widget) { | |
| 46 WidgetToWindowMap::iterator it = window_map_.find(widget); | |
| 47 if (it != window_map_.end()) | |
| 48 window_map_.erase(it); | |
| 49 else | |
| 50 NOTREACHED() << "Attempting to remove non-existing window " << widget; | |
| 51 | |
| 52 if (cursor_->GetCursorWindow() == widget) | |
| 53 ResetCursorLocation(); | |
| 54 } | |
| 55 | |
| 56 DriWindow* DriWindowManager::GetWindow(gfx::AcceleratedWidget widget) { | |
| 57 WidgetToWindowMap::iterator it = window_map_.find(widget); | |
| 58 if (it != window_map_.end()) | |
| 59 return it->second; | |
| 60 | |
| 61 NOTREACHED() << "Attempting to get non-existing window " << widget; | |
| 62 return NULL; | |
| 63 } | |
| 64 | |
| 65 void DriWindowManager::ResetCursorLocation() { | |
| 66 gfx::AcceleratedWidget cursor_widget = gfx::kNullAcceleratedWidget; | |
| 67 gfx::PointF location; | |
| 68 if (!window_map_.empty()) { | |
| 69 WidgetToWindowMap::iterator it = window_map_.begin(); | |
| 70 cursor_widget = it->first; | |
| 71 location = GetDefaultCursorLocation(it->second); | |
| 72 } | |
| 73 | |
| 74 cursor_->MoveCursorTo(cursor_widget, location); | |
| 75 } | |
| 76 | |
| 77 } // namespace ui | |
| OLD | NEW |