| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 #ifndef VIEWS_WIDGET_NATIVE_WIDGET_WAYLAND_H_ | |
| 6 #define VIEWS_WIDGET_NATIVE_WIDGET_WAYLAND_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <wayland-client.h> | |
| 10 | |
| 11 #include "base/memory/scoped_vector.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "ui/gfx/compositor/compositor.h" | |
| 14 #include "ui/gfx/gl/gl_context.h" | |
| 15 #include "ui/gfx/gl/gl_surface.h" | |
| 16 #include "ui/gfx/size.h" | |
| 17 #include "ui/wayland/wayland_widget.h" | |
| 18 #include "views/widget/native_widget_private.h" | |
| 19 #include "views/widget/widget.h" | |
| 20 | |
| 21 typedef struct _cairo_device cairo_device_t; | |
| 22 typedef struct _cairo_surface cairo_surface_t; | |
| 23 | |
| 24 namespace base { | |
| 25 namespace wayland { | |
| 26 union WaylandEvent; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 namespace gfx { | |
| 31 class Rect; | |
| 32 } | |
| 33 | |
| 34 namespace ui { | |
| 35 class ViewProp; | |
| 36 class WaylandDisplay; | |
| 37 class WaylandWindow; | |
| 38 } | |
| 39 | |
| 40 namespace views { | |
| 41 | |
| 42 namespace internal { | |
| 43 class NativeWidgetDelegate; | |
| 44 } | |
| 45 | |
| 46 // Widget implementation for Wayland | |
| 47 class NativeWidgetWayland : public internal::NativeWidgetPrivate, | |
| 48 public ui::CompositorDelegate, | |
| 49 public ui::WaylandWidget { | |
| 50 public: | |
| 51 explicit NativeWidgetWayland(internal::NativeWidgetDelegate* delegate); | |
| 52 virtual ~NativeWidgetWayland(); | |
| 53 | |
| 54 // Overridden from NativeWidget: | |
| 55 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; | |
| 56 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE; | |
| 57 virtual void UpdateFrameAfterFrameChange() OVERRIDE; | |
| 58 virtual bool ShouldUseNativeFrame() const OVERRIDE; | |
| 59 virtual void FrameTypeChanged() OVERRIDE; | |
| 60 virtual Widget* GetWidget() OVERRIDE; | |
| 61 virtual const Widget* GetWidget() const OVERRIDE; | |
| 62 virtual gfx::NativeView GetNativeView() const OVERRIDE; | |
| 63 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; | |
| 64 virtual Widget* GetTopLevelWidget() OVERRIDE; | |
| 65 virtual const ui::Compositor* GetCompositor() const OVERRIDE; | |
| 66 virtual ui::Compositor* GetCompositor() OVERRIDE; | |
| 67 virtual void CalculateOffsetToAncestorWithLayer( | |
| 68 gfx::Point* offset, | |
| 69 ui::Layer** layer_parent) OVERRIDE; | |
| 70 virtual void ReorderLayers() OVERRIDE; | |
| 71 virtual void ViewRemoved(View* view) OVERRIDE; | |
| 72 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; | |
| 73 virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE; | |
| 74 virtual TooltipManager* GetTooltipManager() const OVERRIDE; | |
| 75 virtual bool IsScreenReaderActive() const OVERRIDE; | |
| 76 virtual void SendNativeAccessibilityEvent( | |
| 77 View* view, | |
| 78 ui::AccessibilityTypes::Event event_type) OVERRIDE; | |
| 79 virtual void SetMouseCapture() OVERRIDE; | |
| 80 virtual void ReleaseMouseCapture() OVERRIDE; | |
| 81 virtual bool HasMouseCapture() const OVERRIDE; | |
| 82 virtual InputMethod* CreateInputMethod() OVERRIDE; | |
| 83 virtual void CenterWindow(const gfx::Size& size) OVERRIDE; | |
| 84 virtual void GetWindowPlacement( | |
| 85 gfx::Rect* bounds, | |
| 86 ui::WindowShowState* show_state) const OVERRIDE; | |
| 87 virtual void SetWindowTitle(const string16& title) OVERRIDE; | |
| 88 virtual void SetWindowIcons(const SkBitmap& window_icon, | |
| 89 const SkBitmap& app_icon) OVERRIDE; | |
| 90 virtual void SetAccessibleName(const string16& name) OVERRIDE; | |
| 91 virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE; | |
| 92 virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; | |
| 93 virtual void BecomeModal() OVERRIDE; | |
| 94 virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; | |
| 95 virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; | |
| 96 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | |
| 97 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | |
| 98 virtual void SetSize(const gfx::Size& size) OVERRIDE; | |
| 99 virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; | |
| 100 virtual void MoveToTop() OVERRIDE; | |
| 101 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; | |
| 102 virtual void Close() OVERRIDE; | |
| 103 virtual void CloseNow() OVERRIDE; | |
| 104 virtual void EnableClose(bool enable) OVERRIDE; | |
| 105 virtual void Show() OVERRIDE; | |
| 106 virtual void Hide() OVERRIDE; | |
| 107 virtual void ShowMaximizedWithBounds( | |
| 108 const gfx::Rect& restored_bounds) OVERRIDE; | |
| 109 virtual void ShowWithWindowState(ui::WindowShowState window_state) OVERRIDE; | |
| 110 virtual bool IsVisible() const OVERRIDE; | |
| 111 virtual void Activate() OVERRIDE; | |
| 112 virtual void Deactivate() OVERRIDE; | |
| 113 virtual bool IsActive() const OVERRIDE; | |
| 114 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; | |
| 115 virtual void Maximize() OVERRIDE; | |
| 116 virtual void Minimize() OVERRIDE; | |
| 117 virtual bool IsMaximized() const OVERRIDE; | |
| 118 virtual bool IsMinimized() const OVERRIDE; | |
| 119 virtual void Restore() OVERRIDE; | |
| 120 virtual void SetFullscreen(bool fullscreen) OVERRIDE; | |
| 121 virtual bool IsFullscreen() const OVERRIDE; | |
| 122 virtual void SetOpacity(unsigned char opacity) OVERRIDE; | |
| 123 virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; | |
| 124 virtual bool IsAccessibleWidget() const OVERRIDE; | |
| 125 virtual void RunShellDrag(View* view, | |
| 126 const ui::OSExchangeData& data, | |
| 127 int operation) OVERRIDE; | |
| 128 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | |
| 129 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; | |
| 130 virtual void ClearNativeFocus() OVERRIDE; | |
| 131 virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; | |
| 132 virtual bool ConvertPointFromAncestor( | |
| 133 const Widget* ancestor, gfx::Point* point) const OVERRIDE; | |
| 134 | |
| 135 virtual void OnMotionNotify(WaylandEvent event) OVERRIDE; | |
| 136 virtual void OnButtonNotify(WaylandEvent event) OVERRIDE; | |
| 137 virtual void OnKeyNotify(WaylandEvent event) OVERRIDE; | |
| 138 virtual void OnPointerFocus(WaylandEvent event) OVERRIDE; | |
| 139 virtual void OnKeyboardFocus(WaylandEvent event) OVERRIDE; | |
| 140 | |
| 141 virtual void OnGeometryChange(WaylandEvent event) OVERRIDE; | |
| 142 | |
| 143 private: | |
| 144 typedef ScopedVector<ui::ViewProp> ViewProps; | |
| 145 | |
| 146 // Overridden from ui::CompositorDelegate | |
| 147 virtual void ScheduleDraw(); | |
| 148 | |
| 149 // Overridden from NativeWidget | |
| 150 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | |
| 151 | |
| 152 // Overridden from internal::InputMethodDelegate | |
| 153 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; | |
| 154 | |
| 155 void OnPaint(gfx::Rect damage_area); | |
| 156 | |
| 157 static gboolean IdleRedraw(void* ptr); | |
| 158 | |
| 159 // A delegate implementation that handles events received here. | |
| 160 // See class documentation for Widget in widget.h for a note about ownership. | |
| 161 internal::NativeWidgetDelegate* delegate_; | |
| 162 | |
| 163 scoped_ptr<TooltipManager> tooltip_manager_; | |
| 164 | |
| 165 // The following factory is used to delay destruction. | |
| 166 base::WeakPtrFactory<NativeWidgetWayland> close_widget_factory_; | |
| 167 | |
| 168 // See class documentation for Widget in widget.h for a note about ownership. | |
| 169 Widget::InitParams::Ownership ownership_; | |
| 170 | |
| 171 // Keeps track of mause capture for this widget. | |
| 172 bool has_mouse_capture_; | |
| 173 | |
| 174 // Current window allocation | |
| 175 gfx::Rect allocation_; | |
| 176 // Previous allocation. Used to restore the size and location. | |
| 177 gfx::Rect saved_allocation_; | |
| 178 | |
| 179 // The compositor for accelerated drawing. | |
| 180 scoped_refptr<ui::Compositor> compositor_; | |
| 181 | |
| 182 ViewProps props_; | |
| 183 | |
| 184 // Pointer to the Wayland display. This object doesn't own the pointer. | |
| 185 ui::WaylandDisplay* wayland_display_; | |
| 186 | |
| 187 // Wayland window associated with this widget. | |
| 188 ui::WaylandWindow* wayland_window_; | |
| 189 | |
| 190 // The accelerated surface associated with a Wayland window. | |
| 191 struct wl_egl_window* egl_window_; | |
| 192 | |
| 193 cairo_device_t* device_; | |
| 194 | |
| 195 // Cairo surface associated with the Wayland accelerated surface. This is | |
| 196 // used when we're not using the accelerated painting path. | |
| 197 cairo_surface_t* cairo_surface_; | |
| 198 const cairo_user_data_key_t surface_data_key_; | |
| 199 | |
| 200 // Used to accumulate damaged area between repaints. | |
| 201 // Necessary since Wayland seems to expect at most one paint per frame. | |
| 202 gfx::Rect damage_area_; | |
| 203 | |
| 204 // The GL surface and context used to render when we're using unaccelerated | |
| 205 // rendering. If we're using accelerated rendering, we'll have a compositor | |
| 206 // and the compositor will have these, so we don't need to worry about them. | |
| 207 scoped_refptr<gfx::GLSurface> surface_; | |
| 208 scoped_refptr<gfx::GLContext> context_; | |
| 209 | |
| 210 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWayland); | |
| 211 }; | |
| 212 | |
| 213 } // namespace views | |
| 214 | |
| 215 #endif // VIEWS_WIDGET_NATIVE_WIDGET_WAYLAND_H_ | |
| OLD | NEW |