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