Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/common/gtk_util.h" | 5 #include "chrome/common/gtk_util.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 | 9 |
| 10 #include <cstdarg> | 10 #include <cstdarg> |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 GtkStyle* style = widget->style; | 141 GtkStyle* style = widget->style; |
| 142 PangoFontDescription* font_desc = style->font_desc; | 142 PangoFontDescription* font_desc = style->font_desc; |
| 143 // pango_font_description_set_absolute_size sets the font size in device | 143 // pango_font_description_set_absolute_size sets the font size in device |
| 144 // units, which for us is pixels. | 144 // units, which for us is pixels. |
| 145 pango_font_description_set_absolute_size(font_desc, | 145 pango_font_description_set_absolute_size(font_desc, |
| 146 PANGO_SCALE * size_pixels); | 146 PANGO_SCALE * size_pixels); |
| 147 gtk_widget_modify_font(widget, font_desc); | 147 gtk_widget_modify_font(widget, font_desc); |
| 148 } | 148 } |
| 149 | 149 |
| 150 gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { | 150 gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { |
| 151 int x = 0, y = 0; | 151 gint x, y; |
| 152 gdk_window_get_origin(widget->window, &x, &y); | |
|
tony
2009/08/21 21:13:39
x & y still get filled in if there's no window? I
Evan Stade
2009/08/21 21:43:42
uh, there should always be a window, right? If the
tony
2009/08/21 21:48:51
If there's always a gdk window, can we add a DCHEC
| |
| 152 | 153 |
| 153 if (GTK_IS_WINDOW(widget)) { | 154 if (!GTK_IS_WINDOW(widget)) { |
| 154 gdk_window_get_origin(widget->window, &x, &y); | 155 x += widget->allocation.x; |
| 155 return gfx::Point(x, y); | 156 y += widget->allocation.y; |
| 156 } else { | |
| 157 x = widget->allocation.x; | |
| 158 y = widget->allocation.y; | |
| 159 } | |
| 160 | |
| 161 GtkWidget* parent = gtk_widget_get_parent(widget); | |
| 162 while (parent) { | |
| 163 if (GTK_IS_WINDOW(parent)) { | |
| 164 int window_x, window_y; | |
| 165 // Returns the origin of the window, excluding the frame if one is exists. | |
| 166 gdk_window_get_origin(parent->window, &window_x, &window_y); | |
| 167 x += window_x; | |
| 168 y += window_y; | |
| 169 return gfx::Point(x, y); | |
| 170 } | |
| 171 | |
| 172 if (!GTK_WIDGET_NO_WINDOW(parent)) { | |
| 173 x += parent->allocation.x; | |
| 174 y += parent->allocation.y; | |
| 175 } | |
| 176 | |
| 177 parent = gtk_widget_get_parent(parent); | |
| 178 } | 157 } |
| 179 | 158 |
| 180 return gfx::Point(x, y); | 159 return gfx::Point(x, y); |
| 181 } | 160 } |
| 182 | 161 |
| 183 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { | 162 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { |
| 184 gfx::Point position = GetWidgetScreenPosition(widget); | 163 gfx::Point position = GetWidgetScreenPosition(widget); |
| 185 return gfx::Rect(position.x(), position.y(), | 164 return gfx::Rect(position.x(), position.y(), |
| 186 widget->allocation.width, widget->allocation.height); | 165 widget->allocation.width, widget->allocation.height); |
| 187 } | 166 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 gtk_widget_get_pointer(widget, &x, &y); | 406 gtk_widget_get_pointer(widget, &x, &y); |
| 428 return gfx::Point(x, y); | 407 return gfx::Point(x, y); |
| 429 } | 408 } |
| 430 | 409 |
| 431 GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) { | 410 GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) { |
| 432 GdkPoint point = {ltr ? x : width - x, y}; | 411 GdkPoint point = {ltr ? x : width - x, y}; |
| 433 return point; | 412 return point; |
| 434 } | 413 } |
| 435 | 414 |
| 436 } // namespace gtk_util | 415 } // namespace gtk_util |
| OLD | NEW |