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

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 392018: Enforce that only one constrained window is displayed at once per tab. (Closed)
Patch Set: Set focus correctly on linux Created 11 years, 1 month 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
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 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 // static 113 // static
114 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 114 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
115 return new TabContentsViewGtk(tab_contents); 115 return new TabContentsViewGtk(tab_contents);
116 } 116 }
117 117
118 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) 118 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
119 : TabContentsView(tab_contents), 119 : TabContentsView(tab_contents),
120 floating_(gtk_floating_container_new()), 120 floating_(gtk_floating_container_new()),
121 fixed_(gtk_fixed_new()), 121 fixed_(gtk_fixed_new()),
122 popup_view_(NULL) { 122 popup_view_(NULL),
123 constrained_window_(NULL) {
123 gtk_widget_set_name(fixed_, "chrome-tab-contents-view"); 124 gtk_widget_set_name(fixed_, "chrome-tab-contents-view");
124 g_signal_connect(fixed_, "size-allocate", 125 g_signal_connect(fixed_, "size-allocate",
125 G_CALLBACK(OnSizeAllocate), this); 126 G_CALLBACK(OnSizeAllocate), this);
126 g_signal_connect(floating_.get(), "set-floating-position", 127 g_signal_connect(floating_.get(), "set-floating-position",
127 G_CALLBACK(OnSetFloatingPosition), this); 128 G_CALLBACK(OnSetFloatingPosition), this);
128 129
129 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_); 130 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_);
130 gtk_widget_show(fixed_); 131 gtk_widget_show(fixed_);
131 gtk_widget_show(floating_.get()); 132 gtk_widget_show(floating_.get());
132 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, 133 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
(...skipping 15 matching lines...) Expand all
148 149
149 void TabContentsViewGtk::RemoveBlockedPopupView( 150 void TabContentsViewGtk::RemoveBlockedPopupView(
150 BlockedPopupContainerViewGtk* popup_view) { 151 BlockedPopupContainerViewGtk* popup_view) {
151 DCHECK(popup_view_ == popup_view); 152 DCHECK(popup_view_ == popup_view);
152 gtk_container_remove(GTK_CONTAINER(floating_.get()), popup_view->widget()); 153 gtk_container_remove(GTK_CONTAINER(floating_.get()), popup_view->widget());
153 popup_view_ = NULL; 154 popup_view_ = NULL;
154 } 155 }
155 156
156 void TabContentsViewGtk::AttachConstrainedWindow( 157 void TabContentsViewGtk::AttachConstrainedWindow(
157 ConstrainedWindowGtk* constrained_window) { 158 ConstrainedWindowGtk* constrained_window) {
158 DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(), 159 DCHECK(constrained_window_ == NULL);
159 constrained_window) == constrained_windows_.end());
160 160
161 constrained_windows_.push_back(constrained_window); 161 constrained_window_ = constrained_window;
162 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), 162 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()),
163 constrained_window->widget()); 163 constrained_window->widget());
164 } 164 }
165 165
166 void TabContentsViewGtk::RemoveConstrainedWindow( 166 void TabContentsViewGtk::RemoveConstrainedWindow(
167 ConstrainedWindowGtk* constrained_window) { 167 ConstrainedWindowGtk* constrained_window) {
168 std::vector<ConstrainedWindowGtk*>::iterator item = 168 DCHECK(constrained_window == constrained_window_);
169 find(constrained_windows_.begin(), constrained_windows_.end(),
170 constrained_window);
171 DCHECK(item != constrained_windows_.end());
172 169
170 constrained_window_ = NULL;
173 gtk_container_remove(GTK_CONTAINER(floating_.get()), 171 gtk_container_remove(GTK_CONTAINER(floating_.get()),
174 constrained_window->widget()); 172 constrained_window->widget());
175 constrained_windows_.erase(item);
176 } 173 }
177 174
178 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { 175 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) {
179 requested_size_ = initial_size; 176 requested_size_ = initial_size;
180 gtk_widget_set_size_request(fixed_, requested_size_.width(), 177 gtk_widget_set_size_request(fixed_, requested_size_.width(),
181 requested_size_.height()); 178 requested_size_.height());
182 } 179 }
183 180
184 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( 181 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget(
185 RenderWidgetHost* render_widget_host) { 182 RenderWidgetHost* render_widget_host) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 widget, "x", &value); 440 widget, "x", &value);
444 441
445 int child_y = std::max( 442 int child_y = std::max(
446 allocation->y + allocation->height - requisition.height, 0); 443 allocation->y + allocation->height - requisition.height, 0);
447 g_value_set_int(&value, child_y); 444 g_value_set_int(&value, child_y);
448 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 445 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
449 widget, "y", &value); 446 widget, "y", &value);
450 g_value_unset(&value); 447 g_value_unset(&value);
451 } 448 }
452 449
453 // Place each ConstrainedWindow in the center of the view. 450 // Place the ConstrainedWindow in the center of the view.
454 int half_view_width = std::max((allocation->x + allocation->width) / 2, 0); 451 int half_view_width = std::max((allocation->x + allocation->width) / 2, 0);
455 int half_view_height = std::max((allocation->y + allocation->height) / 2, 0); 452 int half_view_height = std::max((allocation->y + allocation->height) / 2, 0);
456 std::vector<ConstrainedWindowGtk*>::iterator it = 453 if (tab_contents_view->constrained_window_) {
457 tab_contents_view->constrained_windows_.begin(); 454 GtkWidget* widget = tab_contents_view->constrained_window_->widget();
458 std::vector<ConstrainedWindowGtk*>::iterator end =
459 tab_contents_view->constrained_windows_.end();
460 for (; it != end; ++it) {
461 GtkWidget* widget = (*it)->widget();
462 DCHECK(widget->parent == tab_contents_view->floating_.get()); 455 DCHECK(widget->parent == tab_contents_view->floating_.get());
463 456
464 GtkRequisition requisition; 457 GtkRequisition requisition;
465 gtk_widget_size_request(widget, &requisition); 458 gtk_widget_size_request(widget, &requisition);
466 459
467 GValue value = { 0, }; 460 GValue value = { 0, };
468 g_value_init(&value, G_TYPE_INT); 461 g_value_init(&value, G_TYPE_INT);
469 462
470 int child_x = std::max(half_view_width - (requisition.width / 2), 0); 463 int child_x = std::max(half_view_width - (requisition.width / 2), 0);
471 g_value_set_int(&value, child_x); 464 g_value_set_int(&value, child_x);
472 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 465 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
473 widget, "x", &value); 466 widget, "x", &value);
474 467
475 int child_y = std::max(half_view_height - (requisition.height / 2), 0); 468 int child_y = std::max(half_view_height - (requisition.height / 2), 0);
476 g_value_set_int(&value, child_y); 469 g_value_set_int(&value, child_y);
477 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 470 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
478 widget, "y", &value); 471 widget, "y", &value);
479 g_value_unset(&value); 472 g_value_unset(&value);
480 } 473 }
481 } 474 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/browser/views/constrained_window_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698