#include <string>
-#include "ozone/ui/desktop_aura/desktop_window_tree_host_wayland.h"
+#include "ozone/platform/ozone_wayland_window.h"
+#include "ozone/ui/desktop_aura/desktop_window_tree_host_ozone.h"
#include "ozone/ui/events/event_factory_ozone_wayland.h"
+#include "ui/aura/window.h"
#include "ui/events/event_utils.h"
#include "ui/events/platform/platform_event_source.h"
+#include "ui/platform_window/platform_window_delegate.h"
namespace views {
WindowTreeHostDelegateWayland::WindowTreeHostDelegateWayland()
- : current_focus_window_(0),
- handle_event_(true),
- stop_propogation_(false),
- current_dispatcher_(NULL),
- current_capture_(NULL),
- current_active_window_(NULL),
- open_windows_(NULL),
- aura_windows_(NULL) {
- if (ui::PlatformEventSource::GetInstance())
- ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
+ : open_windows_(NULL) {
ui::EventFactoryOzoneWayland::GetInstance()->SetWindowChangeObserver(this);
}
WindowTreeHostDelegateWayland::~WindowTreeHostDelegateWayland() {
}
-void WindowTreeHostDelegateWayland::OnRootWindowCreated(unsigned handle) {
- open_windows().push_back(handle);
-
- if (aura_windows_) {
- aura_windows_->clear();
- delete aura_windows_;
- aura_windows_ = NULL;
- }
+void WindowTreeHostDelegateWayland::OnRootWindowCreated(
+ ui::OzoneWaylandWindow* window) {
+ open_windows().push_back(window);
}
-void WindowTreeHostDelegateWayland::OnRootWindowClosed(unsigned handle) {
- open_windows().remove(handle);
+void WindowTreeHostDelegateWayland::OnRootWindowClosed(
+ ui::OzoneWaylandWindow* window) {
+ open_windows().remove(window);
if (open_windows().empty()) {
delete open_windows_;
open_windows_ = NULL;
- SetActiveWindow(NULL);
-
- ui::PlatformEventSource* event_source =
- ui::PlatformEventSource::GetInstance();
- if (event_source)
- event_source->RemovePlatformEventDispatcher(this);
ui::EventFactoryOzoneWayland::GetInstance()->SetWindowChangeObserver(NULL);
+ return;
}
- if (aura_windows_) {
- aura_windows_->clear();
- delete aura_windows_;
- aura_windows_ = NULL;
- }
-
- if (!current_active_window_ ||
- GetWindowHandle(current_active_window_->window_) != handle ||
- !open_windows_) {
- return;
- }
-
- DCHECK(!current_active_window_->window_parent_);
// Set first top level window in the list of open windows as dispatcher.
// This is just a guess of the window which would eventually be focussed.
// We should set the correct root window as dispatcher in OnWindowFocused.
- const std::list<unsigned>& windows = open_windows();
- DesktopWindowTreeHostWayland* rootWindow =
- DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(
- windows.front());
- SetActiveWindow(rootWindow);
- rootWindow->HandleNativeWidgetActivationChanged(true);
-}
-
-void WindowTreeHostDelegateWayland::SetActiveWindow(
- DesktopWindowTreeHostWayland* dispatcher) {
- current_active_window_ = dispatcher;
- current_dispatcher_ = current_active_window_;
- if (!current_active_window_)
- return;
-
- // Make sure the stacking order is correct. The activated window should be
- // first one in list of open windows.
- std::list<unsigned>& windows = open_windows();
- DCHECK(windows.size());
- unsigned window_handle = current_active_window_->window_;
- if (windows.front() != window_handle) {
- windows.remove(window_handle);
- windows.insert(windows.begin(), window_handle);
- }
-
- current_active_window_->Activate();
+ ui::OzoneWaylandWindow* new_window = open_windows().front();
+ new_window->GetDelegate()->OnActivationChanged(true);
}
-DesktopWindowTreeHostWayland*
-WindowTreeHostDelegateWayland::GetActiveWindow() const {
- return current_active_window_;
-}
-
-void WindowTreeHostDelegateWayland::SetCapture(
- DesktopWindowTreeHostWayland* dispatcher) {
- if (current_capture_)
- current_capture_->OnCaptureReleased();
-
- current_capture_ = dispatcher;
- stop_propogation_ = current_capture_ ? true : false;
- current_dispatcher_ = current_capture_;
- if (!current_dispatcher_)
- current_dispatcher_ = current_active_window_;
-}
-
-DesktopWindowTreeHostWayland*
-WindowTreeHostDelegateWayland::GetCurrentCapture() const {
- return current_capture_;
-}
-
-const std::vector<aura::Window*>&
-WindowTreeHostDelegateWayland::GetAllOpenWindows() {
- if (!aura_windows_) {
- const std::list<unsigned>& windows = open_windows();
- DCHECK(windows.size());
- aura_windows_ = new std::vector<aura::Window*>(windows.size());
- std::transform(
- windows.begin(), windows.end(), aura_windows_->begin(),
- DesktopWindowTreeHostWayland::GetContentWindowForAcceleratedWidget);
- }
-
- return *aura_windows_;
+bool WindowTreeHostDelegateWayland::HasWindowsOpen() const {
+ return open_windows_ ? !open_windows_->empty() : false;
}
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostDelegateWayland, Private implementation:
-void WindowTreeHostDelegateWayland::DispatchMouseEvent(
- ui::MouseEvent* event) {
- if (handle_event_)
- SendEventToProcessor(event);
- else if (event->type() == ui::ET_MOUSE_PRESSED)
- SetCapture(NULL);
-
- // Stop event propogation as this window is acting as event grabber. All
- // event's we create are "cancelable". If in future we use events that are not
- // cancelable, then a check for cancelable events needs to be added here.
- if (stop_propogation_)
- event->StopPropagation();
-}
-
-std::list<unsigned>&
-WindowTreeHostDelegateWayland::open_windows() {
- if (!open_windows_)
- open_windows_ = new std::list<unsigned>();
-
- return *open_windows_;
-}
-
-unsigned
-WindowTreeHostDelegateWayland::GetWindowHandle(gfx::AcceleratedWidget widget) {
- return static_cast<unsigned>(widget);
-}
-
-ui::EventProcessor* WindowTreeHostDelegateWayland::GetEventProcessor() {
- return current_dispatcher_->dispatcher();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowTreeHostDelegateWayland, ui::PlatformEventDispatcher implementation:
-bool WindowTreeHostDelegateWayland::CanDispatchEvent(
- const ui::PlatformEvent& ne) {
- DCHECK(ne);
- return true;
-}
-
-uint32_t WindowTreeHostDelegateWayland::DispatchEvent(
- const ui::PlatformEvent& ne) {
- ui::EventType type = ui::EventTypeFromNative(ne);
- DCHECK(current_dispatcher_);
-
- switch (type) {
- case ui::ET_TOUCH_MOVED:
- case ui::ET_TOUCH_PRESSED:
- case ui::ET_TOUCH_CANCELLED:
- case ui::ET_TOUCH_RELEASED: {
- ui::TouchEvent* touchev = static_cast<ui::TouchEvent*>(ne);
- SendEventToProcessor(touchev);
- break;
- }
- case ui::ET_KEY_PRESSED: {
- ui::KeyEvent* keydown_event = static_cast<ui::KeyEvent*>(ne);
- SendEventToProcessor(keydown_event);
- break;
- }
- case ui::ET_KEY_RELEASED: {
- ui::KeyEvent* keyup_event = static_cast<ui::KeyEvent*>(ne);
- SendEventToProcessor(keyup_event);
+ui::OzoneWaylandWindow*
+WindowTreeHostDelegateWayland::GetWindow(unsigned handle) {
+ ui::OzoneWaylandWindow* window = NULL;
+ const std::list<ui::OzoneWaylandWindow*>& windows = open_windows();
+ std::list<ui::OzoneWaylandWindow*>::const_iterator it;
+ for (it = windows.begin(); it != windows.end(); ++it) {
+ if ((*it)->GetHandle() == handle) {
+ window = *it;
break;
}
- case ui::ET_MOUSEWHEEL: {
- ui::MouseWheelEvent* wheelev = static_cast<ui::MouseWheelEvent*>(ne);
- DispatchMouseEvent(wheelev);
- break;
- }
- case ui::ET_MOUSE_MOVED:
- case ui::ET_MOUSE_DRAGGED:
- case ui::ET_MOUSE_PRESSED:
- case ui::ET_MOUSE_RELEASED:
- case ui::ET_MOUSE_ENTERED:
- case ui::ET_MOUSE_EXITED: {
- ui::MouseEvent* mouseev = static_cast<ui::MouseEvent*>(ne);
- DispatchMouseEvent(mouseev);
- break;
- }
- case ui::ET_SCROLL_FLING_START:
- case ui::ET_SCROLL_FLING_CANCEL:
- case ui::ET_SCROLL: {
- ui::ScrollEvent* scrollev = static_cast<ui::ScrollEvent*>(ne);
- SendEventToProcessor(scrollev);
- break;
- }
- case ui::ET_UMA_DATA:
- break;
- case ui::ET_UNKNOWN:
- break;
- default:
- NOTIMPLEMENTED() << "WindowTreeHostDelegateWayland: unknown event type.";
}
- return ui::POST_DISPATCH_STOP_PROPAGATION;
+
+ return window;
}
////////////////////////////////////////////////////////////////////////////////
-// DesktopWindowTreeHostWayland, WindowChangeObserver implementation:
+// WindowTreeHostDelegateWayland, WindowChangeObserver implementation:
void WindowTreeHostDelegateWayland::OnWindowFocused(unsigned handle) {
- current_focus_window_ = handle;
- // Don't dispatch events in case a window has installed itself as capture
- // window but doesn't have the focus.
- handle_event_ = current_capture_ ? current_focus_window_ ==
- GetWindowHandle(current_capture_->GetAcceleratedWidget()) : true;
- if (GetWindowHandle(current_active_window_->window_) == handle)
- return;
-
- // A new window should not steal focus in case the current window has a open
- // popup.
- if (current_capture_ && current_capture_ != current_active_window_)
+ DCHECK(handle);
+ ui::OzoneWaylandWindow* window = GetWindow(handle);
+ if (!window)
return;
- DesktopWindowTreeHostWayland* window = NULL;
- if (handle)
- window = DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
-
- if (!window || window->window_parent_)
- return;
-
- current_active_window_->HandleNativeWidgetActivationChanged(false);
-
- SetActiveWindow(window);
- window->HandleNativeWidgetActivationChanged(true);
+ window->GetDelegate()->OnActivationChanged(true);
}
void WindowTreeHostDelegateWayland::OnWindowEnter(unsigned handle) {
}
void WindowTreeHostDelegateWayland::OnWindowClose(unsigned handle) {
- // we specially treat grabbed windows in this function, thus the need for
- // current_capture_ always be a valid pointer.
- if (!handle || !current_capture_)
- return;
- if (GetWindowHandle(current_capture_->window_) != handle)
- return;
- DesktopWindowTreeHostWayland* window = NULL;
- window = DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
- window->OnCaptureReleased();
- window->Close();
+ DCHECK(handle);
+ ui::OzoneWaylandWindow* window = GetWindow(handle);
+ DCHECK(window);
+ window->GetDelegate()->OnCloseRequest();
}
void WindowTreeHostDelegateWayland::OnWindowResized(unsigned handle,
unsigned width,
unsigned height) {
- DesktopWindowTreeHostWayland* window =
- DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
+ ui::OzoneWaylandWindow* window = GetWindow(handle);
DCHECK(window);
- window->HandleWindowResize(width, height);
+ const gfx::Rect& current_bounds = window->GetBounds();
+ window->SetBounds(gfx::Rect(current_bounds.x(),
+ current_bounds.y(),
+ width,
+ height));
}
void WindowTreeHostDelegateWayland::OnWindowUnminimized(unsigned handle) {
- DesktopWindowTreeHostWayland* window =
- DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
+ ui::OzoneWaylandWindow* window = GetWindow(handle);
DCHECK(window);
- window->HandleWindowUnminimized();
+ window->GetDelegate()->OnWindowStateChanged(
+ ui::PLATFORM_WINDOW_STATE_MAXIMIZED);
}
-void WindowTreeHostDelegateWayland::OnCommit(unsigned handle,
- const std::string& text) {
- DesktopWindowTreeHostWayland* window =
- DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
+void WindowTreeHostDelegateWayland::OnWindowDeActivated(unsigned windowhandle) {
+ DCHECK(windowhandle);
+ ui::OzoneWaylandWindow* window = GetWindow(windowhandle);
DCHECK(window);
- window->HandleCommit(text);
+ window->GetDelegate()->OnActivationChanged(false);
}
-void WindowTreeHostDelegateWayland::OnPreeditChanged(unsigned handle,
- const std::string& text,
- const std::string& commit) {
- DesktopWindowTreeHostWayland* window =
- DesktopWindowTreeHostWayland::GetHostForAcceleratedWidget(handle);
- DCHECK(window);
- window->HandlePreeditChanged(text, commit);
+void WindowTreeHostDelegateWayland::OnWindowActivated(unsigned windowhandle) {
+ DCHECK(windowhandle);
+ OnWindowFocused(windowhandle);
+}
+
+std::list<ui::OzoneWaylandWindow*>&
+WindowTreeHostDelegateWayland::open_windows() {
+ if (!open_windows_)
+ open_windows_ = new std::list<ui::OzoneWaylandWindow*>();
+
+ return *open_windows_;
}
} // namespace views