Commit 6a2b36e9 authored by erg@chromium.org's avatar erg@chromium.org

GTK: Even more cleanup to access allocation through the accessor.

BUG=79722
TEST=none


Review URL: http://codereview.chromium.org/8921022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114153 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f18c44f
...@@ -1389,7 +1389,9 @@ gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose( ...@@ -1389,7 +1389,9 @@ gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose(
if (!(animation_.IsShowing() || animation_.IsClosing())) if (!(animation_.IsShowing() || animation_.IsClosing()))
return FALSE; return FALSE;
const int height = sender->allocation.height; GtkAllocation allocation;
gtk_widget_get_allocation(sender, &allocation);
const int height = allocation.height;
cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(sender->window)); cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(sender->window));
gdk_cairo_rectangle(cr, &event->area); gdk_cairo_rectangle(cr, &event->area);
......
...@@ -26,9 +26,12 @@ void PopulateSubmenus(GtkWidget* child, gpointer data) { ...@@ -26,9 +26,12 @@ void PopulateSubmenus(GtkWidget* child, gpointer data) {
// Is the cursor over |menu| or one of its parent menus? // Is the cursor over |menu| or one of its parent menus?
bool MotionIsOverMenu(GtkWidget* menu, GdkEventMotion* motion) { bool MotionIsOverMenu(GtkWidget* menu, GdkEventMotion* motion) {
GtkAllocation allocation;
gtk_widget_get_allocation(menu, &allocation);
if (motion->x >= 0 && motion->y >= 0 && if (motion->x >= 0 && motion->y >= 0 &&
motion->x < menu->allocation.width && motion->x < allocation.width &&
motion->y < menu->allocation.height) { motion->y < allocation.height) {
return true; return true;
} }
...@@ -131,8 +134,10 @@ gboolean MenuBarHelper::OnMenuMotionNotify(GtkWidget* menu, ...@@ -131,8 +134,10 @@ gboolean MenuBarHelper::OnMenuMotionNotify(GtkWidget* menu,
last_button = button; last_button = button;
if (x >= 0 && y >= 0 && x < button->allocation.width && GtkAllocation allocation;
y < button->allocation.height) { gtk_widget_get_allocation(button, &allocation);
if (x >= 0 && y >= 0 && x < allocation.width && y < allocation.height) {
if (button != button_showing_menu_) if (button != button_showing_menu_)
delegate_->PopupForButton(button); delegate_->PopupForButton(button);
return TRUE; return TRUE;
......
...@@ -344,7 +344,10 @@ void DraggedViewGtk::SetContainerShapeMask() { ...@@ -344,7 +344,10 @@ void DraggedViewGtk::SetContainerShapeMask() {
cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
else else
cairo_set_operator(cairo_context, CAIRO_OPERATOR_OVER); cairo_set_operator(cairo_context, CAIRO_OPERATOR_OVER);
PaintTab(i, container_, cairo_context, container_->allocation.width);
GtkAllocation allocation;
gtk_widget_get_allocation(container_, &allocation);
PaintTab(i, container_, cairo_context, allocation.width);
} }
if (!attached_) { if (!attached_) {
...@@ -383,6 +386,9 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { ...@@ -383,6 +386,9 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) {
int tab_height = static_cast<int>( int tab_height = static_cast<int>(
kScalingFactor * renderers_[drag_data_->source_tab_index()]->height()); kScalingFactor * renderers_[drag_data_->source_tab_index()]->height());
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
// Draw the render area. // Draw the render area.
BackingStore* backing_store = drag_data_->GetSourceTabContents()-> BackingStore* backing_store = drag_data_->GetSourceTabContents()->
render_view_host()->GetBackingStore(false); render_view_host()->GetBackingStore(false);
...@@ -390,8 +396,8 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { ...@@ -390,8 +396,8 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) {
// This leaves room for the border. // This leaves room for the border.
static_cast<BackingStoreGtk*>(backing_store)->PaintToRect( static_cast<BackingStoreGtk*>(backing_store)->PaintToRect(
gfx::Rect(kDragFrameBorderSize, tab_height, gfx::Rect(kDragFrameBorderSize, tab_height,
widget->allocation.width - kTwiceDragFrameBorderSize, allocation.width - kTwiceDragFrameBorderSize,
widget->allocation.height - tab_height - allocation.height - tab_height -
kDragFrameBorderSize), kDragFrameBorderSize),
GDK_DRAWABLE(widget->window)); GDK_DRAWABLE(widget->window));
} }
...@@ -408,8 +414,8 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { ...@@ -408,8 +414,8 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) {
double offset = kDragFrameBorderSize / 2.0 - 0.5; double offset = kDragFrameBorderSize / 2.0 - 0.5;
double left_x = offset; double left_x = offset;
double top_y = tab_height - kDragFrameBorderSize + offset; double top_y = tab_height - kDragFrameBorderSize + offset;
double right_x = widget->allocation.width - offset; double right_x = allocation.width - offset;
double bottom_y = widget->allocation.height - offset; double bottom_y = allocation.height - offset;
cairo_move_to(cr, left_x, top_y); cairo_move_to(cr, left_x, top_y);
cairo_line_to(cr, left_x, bottom_y); cairo_line_to(cr, left_x, bottom_y);
...@@ -426,11 +432,11 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { ...@@ -426,11 +432,11 @@ gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) {
for (int i = renderers_.size() - 1; i >= 0; i--) { for (int i = renderers_.size() - 1; i >= 0; i--) {
if (i == drag_data_->source_tab_index()) if (i == drag_data_->source_tab_index())
continue; continue;
PaintTab(i, widget, cr, widget->allocation.width); PaintTab(i, widget, cr, allocation.width);
} }
// Painting the active tab last, so that it appears on top. // Painting the active tab last, so that it appears on top.
PaintTab(drag_data_->source_tab_index(), widget, cr, PaintTab(drag_data_->source_tab_index(), widget, cr,
widget->allocation.width); allocation.width);
cairo_destroy(cr); cairo_destroy(cr);
......
...@@ -157,12 +157,15 @@ gboolean TabGtk::OnButtonReleaseEvent(GtkWidget* widget, ...@@ -157,12 +157,15 @@ gboolean TabGtk::OnButtonReleaseEvent(GtkWidget* widget,
} }
} }
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
// Middle mouse up means close the tab, but only if the mouse is over it // Middle mouse up means close the tab, but only if the mouse is over it
// (like a button). // (like a button).
if (event->button == 2 && if (event->button == 2 &&
event->x >= 0 && event->y >= 0 && event->x >= 0 && event->y >= 0 &&
event->x < widget->allocation.width && event->x < allocation.width &&
event->y < widget->allocation.height) { event->y < allocation.height) {
// If the user is currently holding the left mouse button down but hasn't // If the user is currently holding the left mouse button down but hasn't
// moved the mouse yet, a drag hasn't started yet. In that case, clean up // moved the mouse yet, a drag hasn't started yet. In that case, clean up
// some state before closing the tab to avoid a crash. Once the drag has // some state before closing the tab to avoid a crash. Once the drag has
......
...@@ -99,9 +99,13 @@ gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent, ...@@ -99,9 +99,13 @@ gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent,
GtkWidget* widget) { GtkWidget* widget) {
gfx::Point parent_pos = gtk_util::GetWidgetScreenPosition(parent); gfx::Point parent_pos = gtk_util::GetWidgetScreenPosition(parent);
gfx::Point widget_pos = gtk_util::GetWidgetScreenPosition(widget); gfx::Point widget_pos = gtk_util::GetWidgetScreenPosition(widget);
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
return gfx::Rect(widget_pos.x() - parent_pos.x(), return gfx::Rect(widget_pos.x() - parent_pos.x(),
widget_pos.y() - parent_pos.y(), widget_pos.y() - parent_pos.y(),
widget->allocation.width, widget->allocation.height); allocation.width, allocation.height);
} }
} // namespace } // namespace
......
...@@ -78,15 +78,18 @@ static void gtk_preserve_window_realize(GtkWidget* widget) { ...@@ -78,15 +78,18 @@ static void gtk_preserve_window_realize(GtkWidget* widget) {
g_return_if_fail(GTK_IS_PRESERVE_WINDOW(widget)); g_return_if_fail(GTK_IS_PRESERVE_WINDOW(widget));
if (widget->window) { if (widget->window) {
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
gdk_window_reparent(widget->window, gdk_window_reparent(widget->window,
gtk_widget_get_parent_window(widget), gtk_widget_get_parent_window(widget),
widget->allocation.x, allocation.x,
widget->allocation.y); allocation.y);
GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(widget); GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(widget);
if (!priv->delegate_resize) { if (!priv->delegate_resize) {
gdk_window_resize(widget->window, gdk_window_resize(gtk_widget_get_window(widget),
widget->allocation.width, allocation.width,
widget->allocation.height); allocation.height);
} }
widget->style = gtk_style_attach(widget->style, widget->window); widget->style = gtk_style_attach(widget->style, widget->window);
gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment