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.h" 6 7#include "base/bind.h" 8#include "ui/events/event.h" 9#include "ui/events/ozone/evdev/event_factory_evdev.h" 10#include "ui/events/ozone/events_ozone.h" 11#include "ui/events/platform/platform_event_source.h" 12#include "ui/ozone/platform/dri/dri_cursor.h" 13#include "ui/ozone/platform/dri/dri_window_delegate.h" 14#include "ui/ozone/platform/dri/dri_window_delegate_manager.h" 15#include "ui/ozone/platform/dri/dri_window_manager.h" 16#include "ui/platform_window/platform_window_delegate.h" 17 18namespace ui { 19 20DriWindow::DriWindow(PlatformWindowDelegate* delegate, 21 const gfx::Rect& bounds, 22 scoped_ptr<DriWindowDelegate> dri_window_delegate, 23 EventFactoryEvdev* event_factory, 24 DriWindowDelegateManager* window_delegate_manager, 25 DriWindowManager* window_manager) 26 : delegate_(delegate), 27 bounds_(bounds), 28 widget_(dri_window_delegate->GetAcceleratedWidget()), 29 dri_window_delegate_(dri_window_delegate.get()), 30 event_factory_(event_factory), 31 window_delegate_manager_(window_delegate_manager), 32 window_manager_(window_manager) { 33 window_delegate_manager_->AddWindowDelegate(widget_, 34 dri_window_delegate.Pass()); 35 window_manager_->AddWindow(widget_, this); 36} 37 38DriWindow::~DriWindow() { 39 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 40 dri_window_delegate_->Shutdown(); 41 window_manager_->RemoveWindow(widget_); 42 window_delegate_manager_->RemoveWindowDelegate(widget_); 43} 44 45void DriWindow::Initialize() { 46 dri_window_delegate_->Initialize(); 47 dri_window_delegate_->OnBoundsChanged(bounds_); 48 delegate_->OnAcceleratedWidgetAvailable(widget_); 49 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 50} 51 52void DriWindow::Show() {} 53 54void DriWindow::Hide() {} 55 56void DriWindow::Close() {} 57 58void DriWindow::SetBounds(const gfx::Rect& bounds) { 59 bounds_ = bounds; 60 delegate_->OnBoundsChanged(bounds); 61 if (window_manager_->cursor()->GetCursorWindow() == widget_) 62 window_manager_->cursor()->HideCursor(); 63 64 dri_window_delegate_->OnBoundsChanged(bounds); 65 66 if (window_manager_->cursor()->GetCursorWindow() == widget_) 67 window_manager_->cursor()->ShowCursor(); 68} 69 70gfx::Rect DriWindow::GetBounds() { 71 return bounds_; 72} 73 74void DriWindow::SetCapture() {} 75 76void DriWindow::ReleaseCapture() {} 77 78void DriWindow::ToggleFullscreen() {} 79 80void DriWindow::Maximize() {} 81 82void DriWindow::Minimize() {} 83 84void DriWindow::Restore() {} 85 86void DriWindow::SetCursor(PlatformCursor cursor) { 87 window_manager_->cursor()->SetCursor(widget_, cursor); 88} 89 90void DriWindow::MoveCursorTo(const gfx::Point& location) { 91 event_factory_->WarpCursorTo(widget_, location); 92} 93 94bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { 95 DCHECK(ne); 96 Event* event = static_cast<Event*>(ne); 97 if (event->IsMouseEvent() || event->IsScrollEvent()) 98 return window_manager_->cursor()->GetCursorWindow() == widget_; 99 100 return true; 101} 102 103uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { 104 DispatchEventFromNativeUiEvent( 105 native_event, 106 base::Bind(&PlatformWindowDelegate::DispatchEvent, 107 base::Unretained(delegate_))); 108 return POST_DISPATCH_STOP_PROPAGATION; 109} 110 111} // namespace ui 112