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 UI_VIEWS_WIDGET_WIDGET_H_ |
| 6 #define UI_VIEWS_WIDGET_WIDGET_H_ |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" |
| 10 #include "base/task.h" |
| 11 #include "gfx/point.h" |
| 12 #include "ui/views/native_types.h" |
| 13 #include "ui/views/widget/native_widget_listener.h" |
| 14 |
| 15 namespace gfx { |
| 16 class Path; |
| 17 class Rect; |
| 18 } |
| 19 |
| 20 namespace ui { |
| 21 namespace internal { |
| 22 class RootView; |
| 23 } |
| 24 class NativeWidget; |
| 25 class ThemeProvider; |
| 26 class View; |
| 27 |
| 28 //////////////////////////////////////////////////////////////////////////////// |
| 29 // Widget class |
| 30 // |
| 31 // Encapsulates the platform-specific rendering, event receiving and widget |
| 32 // management aspects of the UI framework. |
| 33 // |
| 34 // Owns a RootView and thus a View hierarchy. Can contain child Widgets. |
| 35 // Widget is a platform-independent type that communicates with a platform or |
| 36 // context specific NativeWidget implementation. |
| 37 // |
| 38 // TODO(beng): Consider ownership of this object vs. NativeWidget. |
| 39 class Widget : public internal::NativeWidgetListener { |
| 40 public: |
| 41 explicit Widget(View* contents_view); |
| 42 virtual ~Widget(); |
| 43 |
| 44 bool set_delete_on_destroy(bool delete_on_destroy) { |
| 45 delete_on_destroy_ = delete_on_destroy; |
| 46 } |
| 47 |
| 48 // Initialization. |
| 49 void InitWithNativeViewParent(gfx::NativeView parent, |
| 50 const gfx::Rect& bounds); |
| 51 void InitWithWidgetParent(Widget* parent, const gfx::Rect& bounds); |
| 52 void InitWithViewParent(View* parent, const gfx::Rect& bounds); |
| 53 |
| 54 // Returns the bounding rect of the Widget in screen coordinates. |
| 55 gfx::Rect GetWindowScreenBounds() const; |
| 56 |
| 57 // Returns the bounding rect of the Widget's client area, in screen |
| 58 // coordinates. |
| 59 gfx::Rect GetClientAreaScreenBounds() const; |
| 60 |
| 61 // Sets the bounding rect of the Widget, in the coordinate system of its |
| 62 // parent. |
| 63 void SetBounds(const gfx::Rect& bounds); |
| 64 |
| 65 void SetShape(const gfx::Path& shape); |
| 66 |
| 67 void Show(); |
| 68 void Hide(); |
| 69 |
| 70 void Close(); |
| 71 |
| 72 void MoveAbove(Widget* other); |
| 73 void SetAlwaysOnTop(bool always_on_top); |
| 74 |
| 75 // Causes the specified rectangle to be added to the invalid rectangle for the |
| 76 // Widget. |
| 77 void InvalidateRect(const gfx::Rect& invalid_rect); |
| 78 |
| 79 // Returns a ThemeProvider that can be used to provide resources when |
| 80 // rendering Views associated with this Widget. |
| 81 ThemeProvider* GetThemeProvider() const; |
| 82 |
| 83 NativeWidget* native_widget() const { return native_widget_.get(); } |
| 84 |
| 85 private: |
| 86 // NativeWidgetListener implementation: |
| 87 virtual void OnClose(); |
| 88 virtual void OnDestroy(); |
| 89 virtual void OnDisplayChanged(); |
| 90 virtual bool OnKeyEvent(const KeyEvent& event); |
| 91 virtual void OnMouseCaptureLost(); |
| 92 virtual bool OnMouseEvent(const MouseEvent& event); |
| 93 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event); |
| 94 virtual void OnNativeWidgetCreated(); |
| 95 virtual void OnPaint(gfx::Canvas* canvas); |
| 96 virtual void OnSizeChanged(const gfx::Size& size); |
| 97 virtual void OnWorkAreaChanged(); |
| 98 |
| 99 // Causes the Widget to be destroyed immediately. |
| 100 void CloseNow(); |
| 101 |
| 102 // A NativeWidget implementation. This can be changed dynamically to a |
| 103 // different implementation during the lifetime of the Widget. |
| 104 scoped_ptr<NativeWidget> native_widget_; |
| 105 |
| 106 // A RootView that owns the View hierarchy within this Widget. |
| 107 scoped_ptr<internal::RootView> root_view_; |
| 108 |
| 109 // True when any mouse button is pressed. |
| 110 bool is_mouse_button_pressed_; |
| 111 |
| 112 // The following are used to detect duplicate mouse move events and not |
| 113 // deliver them. Displaying a window may result in the system generating |
| 114 // duplicate move events even though the mouse hasn't moved. |
| 115 bool last_mouse_event_was_move_; |
| 116 gfx::Point last_mouse_event_position_; |
| 117 |
| 118 // Handles closing the Widget after a return to the message loop to allow the |
| 119 // stack to unwind. |
| 120 ScopedRunnableMethodFactory<Widget> close_widget_factory_; |
| 121 |
| 122 // True if the Widget should be automatically deleted when it is destroyed. |
| 123 bool delete_on_destroy_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(Widget); |
| 126 }; |
| 127 |
| 128 } // namespace ui |
| 129 |
| 130 #endif // UI_VIEWS_WIDGET_WIDGET_H_ |
| 131 |
OLD | NEW |