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.
5 #include "ui/ozone/platform/dri/dri_window_manager.h"
7 #include "base/logging.h"
8 #include "ui/ozone/platform/dri/dri_cursor.h"
9 #include "ui/ozone/platform/dri/dri_window.h"
15 gfx::PointF
GetDefaultCursorLocation(DriWindow
* window
) {
16 return gfx::PointF(window
->GetBounds().width() / 2,
17 window
->GetBounds().height() / 2);
22 DriWindowManager::DriWindowManager(HardwareCursorDelegate
* cursor_delegate
)
23 : last_allocated_widget_(0), cursor_(new DriCursor(cursor_delegate
, this)) {
26 DriWindowManager::~DriWindowManager() {
29 gfx::AcceleratedWidget
DriWindowManager::NextAcceleratedWidget() {
30 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an
32 return ++last_allocated_widget_
;
35 void DriWindowManager::AddWindow(gfx::AcceleratedWidget widget
,
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.";
41 if (cursor_
->GetCursorWindow() == gfx::kNullAcceleratedWidget
)
42 ResetCursorLocation();
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
);
50 NOTREACHED() << "Attempting to remove non-existing window " << widget
;
52 if (cursor_
->GetCursorWindow() == widget
)
53 ResetCursorLocation();
56 DriWindow
* DriWindowManager::GetWindow(gfx::AcceleratedWidget widget
) {
57 WidgetToWindowMap::iterator it
= window_map_
.find(widget
);
58 if (it
!= window_map_
.end())
61 NOTREACHED() << "Attempting to get non-existing window " << widget
;
65 void DriWindowManager::ResetCursorLocation() {
66 gfx::AcceleratedWidget cursor_widget
= gfx::kNullAcceleratedWidget
;
68 if (!window_map_
.empty()) {
69 WidgetToWindowMap::iterator it
= window_map_
.begin();
70 cursor_widget
= it
->first
;
71 location
= GetDefaultCursorLocation(it
->second
);
74 cursor_
->MoveCursorTo(cursor_widget
, location
);