Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: chrome/browser/gtk/info_bubble_gtk.h

Issue 316006: GTK: Try to position info bubbles onscreen. (Closed)
Patch Set: merge Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/gtk/info_bubble_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is the GTK implementation of InfoBubbles. InfoBubbles are like 5 // This is the GTK implementation of InfoBubbles. InfoBubbles are like
6 // dialogs, but they point to a given element on the screen. You should call 6 // dialogs, but they point to a given element on the screen. You should call
7 // InfoBubbleGtk::Show, which will create and display a bubble. The object is 7 // InfoBubbleGtk::Show, which will create and display a bubble. The object is
8 // self deleting, when the bubble is closed, you will be notified via 8 // self deleting, when the bubble is closed, you will be notified via
9 // InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the 9 // InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the
10 // underlying object will be destroyed. You can also close and destroy the 10 // underlying object will be destroyed. You can also close and destroy the
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // grabs (e.g. GtkComboBox), this method should be called after a widget 65 // grabs (e.g. GtkComboBox), this method should be called after a widget
66 // releases the grabs so we can reacquire them. Note that this causes a race 66 // releases the grabs so we can reacquire them. Note that this causes a race
67 // condition; another client could grab them before we do (ideally, GDK would 67 // condition; another client could grab them before we do (ideally, GDK would
68 // transfer the grabs back to us when the widget releases them). The window 68 // transfer the grabs back to us when the widget releases them). The window
69 // is small, though, and the worst-case scenario for this seems to just be 69 // is small, though, and the worst-case scenario for this seems to just be
70 // that the content's widgets will appear inactive even after the user clicks 70 // that the content's widgets will appear inactive even after the user clicks
71 // in them. 71 // in them.
72 void HandlePointerAndKeyboardUngrabbedByContent(); 72 void HandlePointerAndKeyboardUngrabbedByContent();
73 73
74 private: 74 private:
75 // Where should the arrow be placed relative to the bubble?
76 enum ArrowLocationGtk {
77 // TODO(derat): Support placing arrows on the bottoms of the bubbles.
78 ARROW_LOCATION_TOP_LEFT,
79 ARROW_LOCATION_TOP_RIGHT,
80 };
81
82 enum FrameType {
83 FRAME_MASK,
84 FRAME_STROKE,
85 };
86
75 explicit InfoBubbleGtk(GtkThemeProvider* provider); 87 explicit InfoBubbleGtk(GtkThemeProvider* provider);
76 virtual ~InfoBubbleGtk(); 88 virtual ~InfoBubbleGtk();
77 89
78 // Creates the InfoBubble. 90 // Creates the InfoBubble.
79 void Init(GtkWindow* toplevel_window, 91 void Init(GtkWindow* toplevel_window,
80 const gfx::Rect& rect, 92 const gfx::Rect& rect,
81 GtkWidget* content); 93 GtkWidget* content);
82 94
95 // Make the points for our polygon frame, either for fill (the mask), or for
96 // when we stroke the border.
97 static std::vector<GdkPoint> MakeFramePolygonPoints(
98 ArrowLocationGtk arrow_location,
99 int width,
100 int height,
101 FrameType type);
102
103 // Get the location where the arrow should be placed (which is a function of
104 // whether the user's language is LTR/RTL and of the direction that the bubble
105 // should be facing to fit onscreen). |arrow_x| is the X component in screen
106 // coordinates of the point at which the bubble's arrow should be aimed, and
107 // |width| is the bubble's width.
108 static ArrowLocationGtk GetArrowLocation(int arrow_x, int width);
109
110 // Updates |arrow_location_| based on the toplevel window's current position
111 // and the bubble's size. If the location changes, moves and reshapes the
112 // window and returns true.
113 bool UpdateArrowLocation();
114
115 // Reshapes the window and updates |mask_region_|.
116 void UpdateWindowShape();
117
83 // Calculate the current screen position for the bubble's window (per 118 // Calculate the current screen position for the bubble's window (per
84 // |toplevel_window_|'s position as of its most-recent ConfigureNotify event 119 // |toplevel_window_|'s position as of its most-recent ConfigureNotify event
85 // and |rect_|) and move it there. 120 // and |rect_|) and move it there.
86 void MoveWindow(); 121 void MoveWindow();
87 122
88 // Restack the bubble's window directly above |toplevel_window_|. 123 // Restack the bubble's window directly above |toplevel_window_|.
89 void StackWindow(); 124 void StackWindow();
90 125
91 // Sets the delegate. 126 // Sets the delegate.
92 void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; } 127 void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; }
93 128
94 // Closes the window and notifies the delegate. |closed_by_escape| is true if 129 // Closes the window and notifies the delegate. |closed_by_escape| is true if
95 // the close is the result of pressing escape. 130 // the close is the result of pressing escape.
96 void CloseInternal(bool closed_by_escape); 131 void CloseInternal(bool closed_by_escape);
97 132
98 // Grab (in the X sense) the pointer and keyboard. This is needed to make 133 // Grab (in the X sense) the pointer and keyboard. This is needed to make
99 // sure that we have the input focus. 134 // sure that we have the input focus.
100 void GrabPointerAndKeyboard(); 135 void GrabPointerAndKeyboard();
101 136
102 static gboolean HandleEscapeThunk(GtkAccelGroup* group, 137 static gboolean HandleEscapeThunk(GtkAccelGroup* group,
103 GObject* acceleratable, 138 GObject* acceleratable,
104 guint keyval, 139 guint keyval,
105 GdkModifierType modifier, 140 GdkModifierType modifier,
106 gpointer user_data) { 141 gpointer user_data) {
107 return reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleEscape(); 142 return reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleEscape();
108 } 143 }
109 gboolean HandleEscape(); 144 gboolean HandleEscape();
110 145
146 static gboolean HandleExposeThunk(GtkWidget* widget,
147 GdkEventExpose* event,
148 gpointer user_data) {
149 return reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleExpose();
150 }
151 gboolean HandleExpose();
152
111 static void HandleSizeAllocateThunk(GtkWidget* widget, 153 static void HandleSizeAllocateThunk(GtkWidget* widget,
112 GtkAllocation* allocation, 154 GtkAllocation* allocation,
113 gpointer user_data) { 155 gpointer user_data) {
114 reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleSizeAllocate(); 156 reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleSizeAllocate();
115 } 157 }
116 void HandleSizeAllocate(); 158 void HandleSizeAllocate();
117 159
118 static gboolean HandleButtonPressThunk(GtkWidget* widget, 160 static gboolean HandleButtonPressThunk(GtkWidget* widget,
119 GdkEventButton* event, 161 GdkEventButton* event,
120 gpointer user_data) { 162 gpointer user_data) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 GtkWindow* toplevel_window_; 211 GtkWindow* toplevel_window_;
170 212
171 // Provides an offset from |toplevel_window_|'s origin for MoveWindow() to 213 // Provides an offset from |toplevel_window_|'s origin for MoveWindow() to
172 // use. 214 // use.
173 gfx::Rect rect_; 215 gfx::Rect rect_;
174 216
175 // The current shape of |window_| (used to test whether clicks fall in it or 217 // The current shape of |window_| (used to test whether clicks fall in it or
176 // not). 218 // not).
177 GdkRegion* mask_region_; 219 GdkRegion* mask_region_;
178 220
221 // Where should the arrow be drawn relative to the bubble?
222 ArrowLocationGtk arrow_location_;
223
179 NotificationRegistrar registrar_; 224 NotificationRegistrar registrar_;
180 225
181 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); 226 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk);
182 }; 227 };
183 228
184 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ 229 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/gtk/info_bubble_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698