| 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/browser/gtk/constrained_window_gtk.h" | 5 #include "chrome/browser/gtk/constrained_window_gtk.h" |
| 6 | 6 |
| 7 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" | 8 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 9 #include "chrome/common/gtk_util.h" | 9 #include "chrome/common/gtk_util.h" |
| 10 | 10 |
| 11 ConstrainedWindowGtk::ConstrainedWindowGtk( | 11 ConstrainedWindowGtk::ConstrainedWindowGtk( |
| 12 TabContents* owner, ConstrainedWindowGtkDelegate* delegate) | 12 TabContents* owner, ConstrainedWindowGtkDelegate* delegate) |
| 13 : owner_(owner), | 13 : owner_(owner), |
| 14 delegate_(delegate) { | 14 delegate_(delegate), |
| 15 visible_(false) { |
| 15 DCHECK(owner); | 16 DCHECK(owner); |
| 16 DCHECK(delegate); | 17 DCHECK(delegate); |
| 17 GtkWidget* dialog = delegate->GetWidgetRoot(); | 18 GtkWidget* dialog = delegate->GetWidgetRoot(); |
| 18 | 19 |
| 19 // Unlike other users of CreateBorderBin, we need a dedicated frame around | 20 // Unlike other users of CreateBorderBin, we need a dedicated frame around |
| 20 // our "window". | 21 // our "window". |
| 21 GtkWidget* ebox = gtk_event_box_new(); | 22 GtkWidget* ebox = gtk_event_box_new(); |
| 22 GtkWidget* frame = gtk_frame_new(NULL); | 23 GtkWidget* frame = gtk_frame_new(NULL); |
| 23 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); | 24 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); |
| 24 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 25 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 25 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), | 26 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
| 26 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder, | 27 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder, |
| 27 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder); | 28 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder); |
| 28 gtk_container_add(GTK_CONTAINER(alignment), dialog); | 29 gtk_container_add(GTK_CONTAINER(alignment), dialog); |
| 29 gtk_container_add(GTK_CONTAINER(frame), alignment); | 30 gtk_container_add(GTK_CONTAINER(frame), alignment); |
| 30 gtk_container_add(GTK_CONTAINER(ebox), frame); | 31 gtk_container_add(GTK_CONTAINER(ebox), frame); |
| 31 border_.Own(ebox); | 32 border_.Own(ebox); |
| 32 | |
| 33 gtk_widget_show_all(border_.get()); | |
| 34 | |
| 35 // We collaborate with TabContentsViewGtk and stick ourselves in the | |
| 36 // TabContentsViewGtk's floating container. | |
| 37 ContainingView()->AttachConstrainedWindow(this); | |
| 38 } | 33 } |
| 39 | 34 |
| 40 ConstrainedWindowGtk::~ConstrainedWindowGtk() { | 35 ConstrainedWindowGtk::~ConstrainedWindowGtk() { |
| 41 border_.Destroy(); | 36 border_.Destroy(); |
| 42 } | 37 } |
| 43 | 38 |
| 39 void ConstrainedWindowGtk::ShowConstrainedWindow() { |
| 40 gtk_widget_show_all(border_.get()); |
| 41 |
| 42 // We collaborate with TabContentsViewGtk and stick ourselves in the |
| 43 // TabContentsViewGtk's floating container. |
| 44 ContainingView()->AttachConstrainedWindow(this); |
| 45 |
| 46 visible_ = true; |
| 47 } |
| 48 |
| 44 void ConstrainedWindowGtk::CloseConstrainedWindow() { | 49 void ConstrainedWindowGtk::CloseConstrainedWindow() { |
| 45 ContainingView()->RemoveConstrainedWindow(this); | 50 if (visible_) |
| 51 ContainingView()->RemoveConstrainedWindow(this); |
| 46 delegate_->DeleteDelegate(); | 52 delegate_->DeleteDelegate(); |
| 47 owner_->WillClose(this); | 53 owner_->WillClose(this); |
| 48 | 54 |
| 49 delete this; | 55 delete this; |
| 50 } | 56 } |
| 51 | 57 |
| 52 TabContentsViewGtk* ConstrainedWindowGtk::ContainingView() { | 58 TabContentsViewGtk* ConstrainedWindowGtk::ContainingView() { |
| 53 return static_cast<TabContentsViewGtk*>(owner_->view()); | 59 return static_cast<TabContentsViewGtk*>(owner_->view()); |
| 54 } | 60 } |
| 55 | 61 |
| 56 // static | 62 // static |
| 57 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( | 63 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( |
| 58 TabContents* parent, | 64 TabContents* parent, |
| 59 ConstrainedWindowGtkDelegate* delegate) { | 65 ConstrainedWindowGtkDelegate* delegate) { |
| 60 return new ConstrainedWindowGtk(parent, delegate); | 66 return new ConstrainedWindowGtk(parent, delegate); |
| 61 } | 67 } |
| OLD | NEW |