OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_UI_PANELS_PANEL_GTK_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_GTK_H_ |
| 7 |
| 8 #include <gtk/gtk.h> |
| 9 #include <map> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer.h" |
| 14 #include "chrome/browser/ui/panels/native_panel.h" |
| 15 #include "ui/base/animation/animation_delegate.h" |
| 16 #include "ui/base/gtk/gtk_signal.h" |
| 17 #include "ui/base/x/active_window_watcher_x_observer.h" |
| 18 #include "ui/gfx/rect.h" |
| 19 |
| 20 class Panel; |
| 21 class PanelBoundsAnimation; |
| 22 class PanelTitlebarGtk; |
| 23 class PanelDragGtk; |
| 24 class GtkNativePanelTesting; |
| 25 |
| 26 namespace gfx { |
| 27 class Image; |
| 28 } |
| 29 |
| 30 // An implementation of the native panel in GTK. |
| 31 class PanelGtk : public NativePanel, |
| 32 public ui::ActiveWindowWatcherXObserver, |
| 33 public ui::AnimationDelegate { |
| 34 public: |
| 35 enum PaintState { |
| 36 PAINT_AS_ACTIVE, |
| 37 PAINT_AS_INACTIVE, |
| 38 PAINT_AS_MINIMIZED, |
| 39 PAINT_FOR_ATTENTION |
| 40 }; |
| 41 |
| 42 PanelGtk(Panel* panel, const gfx::Rect& bounds); |
| 43 virtual ~PanelGtk(); |
| 44 |
| 45 void Init(); |
| 46 |
| 47 // Overridden from NativePanel. |
| 48 virtual void ShowPanel() OVERRIDE; |
| 49 virtual void ShowPanelInactive() OVERRIDE; |
| 50 virtual gfx::Rect GetPanelBounds() const OVERRIDE; |
| 51 virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE; |
| 52 virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE; |
| 53 virtual void ClosePanel() OVERRIDE; |
| 54 virtual void ActivatePanel() OVERRIDE; |
| 55 virtual void DeactivatePanel() OVERRIDE; |
| 56 virtual bool IsPanelActive() const OVERRIDE; |
| 57 virtual void PreventActivationByOS(bool prevent_activation) OVERRIDE; |
| 58 virtual gfx::NativeWindow GetNativePanelHandle() OVERRIDE; |
| 59 virtual void UpdatePanelTitleBar() OVERRIDE; |
| 60 virtual void UpdatePanelLoadingAnimations(bool should_animate) OVERRIDE; |
| 61 virtual FindBar* CreatePanelFindBar() OVERRIDE; |
| 62 virtual void NotifyPanelOnUserChangedTheme() OVERRIDE; |
| 63 virtual void PanelCut() OVERRIDE; |
| 64 virtual void PanelCopy() OVERRIDE; |
| 65 virtual void PanelPaste() OVERRIDE; |
| 66 virtual void DrawAttention(bool draw_attention) OVERRIDE; |
| 67 virtual bool IsDrawingAttention() const OVERRIDE; |
| 68 virtual bool PreHandlePanelKeyboardEvent( |
| 69 const content::NativeWebKeyboardEvent& event, |
| 70 bool* is_keyboard_shortcut) OVERRIDE; |
| 71 virtual void HandlePanelKeyboardEvent( |
| 72 const content::NativeWebKeyboardEvent& event) OVERRIDE; |
| 73 virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE; |
| 74 virtual void PanelExpansionStateChanging( |
| 75 Panel::ExpansionState old_state, |
| 76 Panel::ExpansionState new_state) OVERRIDE; |
| 77 virtual void AttachWebContents(content::WebContents* contents) OVERRIDE; |
| 78 virtual void DetachWebContents(content::WebContents* contents) OVERRIDE; |
| 79 virtual Browser* GetPanelBrowser() const OVERRIDE; |
| 80 // These sizes are in screen coordinates. |
| 81 virtual gfx::Size WindowSizeFromContentSize( |
| 82 const gfx::Size& content_size) const OVERRIDE; |
| 83 virtual gfx::Size ContentSizeFromWindowSize( |
| 84 const gfx::Size& window_size) const OVERRIDE; |
| 85 virtual int TitleOnlyHeight() const OVERRIDE; |
| 86 virtual void EnsurePanelFullyVisible() OVERRIDE; |
| 87 virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; |
| 88 virtual void EnableResizeByMouse(bool enable) OVERRIDE; |
| 89 virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; |
| 90 |
| 91 virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; |
| 92 |
| 93 // Overridden from ActiveWindowWatcherXObserver. |
| 94 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; |
| 95 |
| 96 bool UsingDefaultTheme() const; |
| 97 |
| 98 Panel* panel() const { return panel_.get(); } |
| 99 PaintState paint_state() const { return paint_state_; } |
| 100 PanelTitlebarGtk* titlebar() const { return titlebar_.get(); } |
| 101 |
| 102 private: |
| 103 friend class GtkNativePanelTesting; |
| 104 |
| 105 // Applies our custom window shape with rounded top corners. |
| 106 void UpdateWindowShape(int width, int height); |
| 107 |
| 108 // Checks to see if the mouse pointer at |x|, |y| is over the border of the |
| 109 // custom frame (a spot that should trigger a window resize). Returns true if |
| 110 // it should and sets |edge|. |
| 111 bool GetWindowEdge(int x, int y, GdkWindowEdge* edge) const; |
| 112 |
| 113 // Connect/disconnect accelerators for keyboard shortcut support. |
| 114 void ConnectAccelerators(); |
| 115 void DisconnectAccelerators(); |
| 116 |
| 117 // Returns the image to paint the frame. |
| 118 const gfx::Image* GetFrameBackground() const; |
| 119 const gfx::Image* GetDefaultFrameBackground() const; |
| 120 const gfx::Image* GetThemedFrameBackground() const; |
| 121 |
| 122 // Animation when panel is first shown. |
| 123 void RevealPanel(); |
| 124 |
| 125 void StartBoundsAnimation(const gfx::Rect& from_bounds, |
| 126 const gfx::Rect& to_bounds); |
| 127 bool IsAnimatingBounds() const; |
| 128 |
| 129 // Overridden from AnimationDelegate: |
| 130 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 131 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 132 |
| 133 // Creates helper for handling drags if not already created. |
| 134 void EnsureDragHelperCreated(); |
| 135 |
| 136 void SetBoundsInternal(const gfx::Rect& bounds, bool animate); |
| 137 |
| 138 void LoadingAnimationCallback(); |
| 139 |
| 140 // Returns the size of the window frame around the client content area. |
| 141 gfx::Size GetNonClientFrameSize() const; |
| 142 |
| 143 // Invalidate window to force repaint. |
| 144 void InvalidateWindow(); |
| 145 |
| 146 // Callback for accelerator activation. |user_data| stores the command id |
| 147 // of the matched accelerator. |
| 148 static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group, |
| 149 GObject* acceleratable, |
| 150 guint keyval, |
| 151 GdkModifierType modifier, |
| 152 void* user_data); |
| 153 |
| 154 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnMainWindowDeleteEvent, |
| 155 GdkEvent*); |
| 156 CHROMEGTK_CALLBACK_0(PanelGtk, void, OnMainWindowDestroy); |
| 157 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnConfigure, GdkEventConfigure*); |
| 158 // Callback for when the custom frame alignment needs to be redrawn. |
| 159 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnCustomFrameExpose, |
| 160 GdkEventExpose*); |
| 161 // Key press event callback. |
| 162 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnKeyPress, GdkEventKey*); |
| 163 // Mouse move and button press callbacks. If mouse hits titlebar, |
| 164 // the titlebar gets the event, else the window gets the button press. |
| 165 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnMouseMoveEvent, |
| 166 GdkEventMotion*); |
| 167 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, OnButtonPressEvent, |
| 168 GdkEventButton*); |
| 169 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, |
| 170 OnTitlebarButtonPressEvent, GdkEventButton*); |
| 171 CHROMEGTK_CALLBACK_1(PanelGtk, gboolean, |
| 172 OnTitlebarButtonReleaseEvent, GdkEventButton*); |
| 173 |
| 174 scoped_ptr<Panel> panel_; |
| 175 gfx::Rect bounds_; |
| 176 |
| 177 // True after panel has been shown. |
| 178 bool is_shown_; |
| 179 |
| 180 scoped_ptr<PanelDragGtk> drag_helper_; |
| 181 |
| 182 // The configure size of the current window, used to figure out whether to |
| 183 // ignore later configure events. See OnConfigure() for more information. |
| 184 gfx::Size configure_size_; |
| 185 |
| 186 // Indicates different painting state, active, drawing attention or else. |
| 187 PaintState paint_state_; |
| 188 |
| 189 // Indicates that the panel is currently drawing attention. |
| 190 bool is_drawing_attention_; |
| 191 |
| 192 // Used to animate the bounds change. |
| 193 scoped_ptr<PanelBoundsAnimation> bounds_animator_; |
| 194 gfx::Rect animation_start_bounds_; |
| 195 |
| 196 // This records the bounds set on the last animation progress notification. |
| 197 // We need this for the case where a new bounds animation starts before the |
| 198 // current one completes. In this case, we want to start the new animation |
| 199 // from where the last one left. |
| 200 gfx::Rect last_animation_progressed_bounds_; |
| 201 |
| 202 // The timer used to update frames for the Loading Animation. |
| 203 base::RepeatingTimer<PanelGtk> loading_animation_timer_; |
| 204 |
| 205 // The current window cursor. We set it to a resize cursor when over the |
| 206 // custom frame border. We set it to NULL if we want the default cursor. |
| 207 GdkCursor* frame_cursor_; |
| 208 |
| 209 // True if the window manager thinks the window is active. Not all window |
| 210 // managers keep track of this state (_NET_ACTIVE_WINDOW), in which case |
| 211 // this will always be true. |
| 212 bool is_active_; |
| 213 |
| 214 // Top level window. |
| 215 GtkWindow* window_; |
| 216 // GtkAlignment that holds the interior components of the chromium window. |
| 217 // This is used to draw the custom frame border and content shadow. |
| 218 GtkWidget* window_container_; |
| 219 // VBox that holds everything (titlebar, web contents). |
| 220 GtkWidget* window_vbox_; |
| 221 // EventBox that holds web contents. |
| 222 GtkWidget* render_area_event_box_; |
| 223 // We insert and remove WebContents GtkWidgets into this expanded. |
| 224 GtkWidget* contents_expanded_; |
| 225 |
| 226 // The accelerator group used to handle accelerators, owned by this object. |
| 227 GtkAccelGroup* accel_group_; |
| 228 |
| 229 // The container for the titlebar. |
| 230 scoped_ptr<PanelTitlebarGtk> titlebar_; |
| 231 |
| 232 DISALLOW_COPY_AND_ASSIGN(PanelGtk); |
| 233 }; |
| 234 |
| 235 #endif // CHROME_BROWSER_UI_PANELS_PANEL_GTK_H_ |
OLD | NEW |