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

Side by Side Diff: chrome/browser/ui/gtk/constrained_html_delegate_gtk.cc

Issue 8220026: Add new methods to create constrained windows for print preview and release the internal TabConte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/webui/constrained_html_ui.h" 5 #include "chrome/browser/ui/webui/constrained_html_ui.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" 8 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
9 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" 9 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" 11 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
12 #include "chrome/browser/ui/webui/html_dialog_ui.h" 12 #include "chrome/browser/ui/webui/html_dialog_ui.h"
13 #include "content/browser/renderer_host/render_view_host.h" 13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "content/common/notification_source.h" 15 #include "content/common/notification_source.h"
16 #include "ui/base/gtk/gtk_hig_constants.h" 16 #include "ui/base/gtk/gtk_hig_constants.h"
17 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
18 18
19 class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate, 19 class ConstrainedHtmlDelegateGtk : public ConstrainedWindowGtkDelegate,
20 public HtmlDialogTabContentsDelegate, 20 public HtmlDialogTabContentsDelegate,
21 public ConstrainedHtmlUIDelegate { 21 public ConstrainedHtmlUIDelegate {
22 public: 22 public:
23 ConstrainedHtmlDelegateGtk(Profile* profile, 23 ConstrainedHtmlDelegateGtk(Profile* profile,
24 HtmlDialogUIDelegate* delegate); 24 HtmlDialogUIDelegate* delegate);
25 25
26 virtual ~ConstrainedHtmlDelegateGtk(); 26 virtual ~ConstrainedHtmlDelegateGtk() {
27 if (release_tab_on_close_)
28 ignore_result(tab_.release());
29 }
30
31 TabContentsWrapper* tab() {
32 return tab_.get();
33 }
27 34
28 // ConstrainedWindowGtkDelegate ---------------------------------------------- 35 // ConstrainedWindowGtkDelegate ----------------------------------------------
29 virtual GtkWidget* GetWidgetRoot() OVERRIDE { 36 virtual GtkWidget* GetWidgetRoot() OVERRIDE {
30 return tab_contents_container_.widget(); 37 return tab_contents_container_.widget();
31 } 38 }
32 virtual GtkWidget* GetFocusWidget() OVERRIDE { 39 virtual GtkWidget* GetFocusWidget() OVERRIDE {
33 return tab_.tab_contents()->GetContentNativeView(); 40 return tab_->tab_contents()->GetContentNativeView();
34 } 41 }
35 virtual void DeleteDelegate() OVERRIDE { 42 virtual void DeleteDelegate() OVERRIDE {
36 if (!closed_via_webui_) 43 if (!closed_via_webui_)
37 html_delegate_->OnDialogClosed(""); 44 html_delegate_->OnDialogClosed("");
38 delete this; 45 delete this;
39 } 46 }
40
41 // ConstrainedHtmlDelegate ---------------------------------------------
42 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE;
43 virtual void OnDialogCloseFromWebUI() OVERRIDE;
44 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { 47 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE {
45 *color = ui::kGdkWhite; 48 *color = ui::kGdkWhite;
46 return true; 49 return true;
47 } 50 }
48 51
52 // ConstrainedHtmlUIDelegate -------------------------------------------------
53 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE {
54 return html_delegate_;
55 }
56 virtual void OnDialogCloseFromWebUI() OVERRIDE {
57 closed_via_webui_ = true;
58 window_->CloseConstrainedWindow();
59 }
60
61 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE {
62 release_tab_on_close_ = true;
63 }
64
49 // HtmlDialogTabContentsDelegate --------------------------------------------- 65 // HtmlDialogTabContentsDelegate ---------------------------------------------
50 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) 66 virtual void HandleKeyboardEvent(
51 OVERRIDE {} 67 const NativeWebKeyboardEvent& event) OVERRIDE {
68 }
52 69
53 void set_window(ConstrainedWindow* window) { 70 void set_window(ConstrainedWindow* window) {
54 window_ = window; 71 window_ = window;
55 } 72 }
56 73
57 private: 74 private:
58 TabContentsWrapper tab_; 75 scoped_ptr<TabContentsWrapper> tab_;
59 TabContentsContainerGtk tab_contents_container_; 76 TabContentsContainerGtk tab_contents_container_;
60 HtmlDialogUIDelegate* html_delegate_; 77 HtmlDialogUIDelegate* html_delegate_;
61 78
62 // The constrained window that owns |this|. It's saved here because it needs 79 // The constrained window that owns |this|. It's saved here because it needs
63 // to be closed in response to the WebUI OnDialogClose callback. 80 // to be closed in response to the WebUI OnDialogClose callback.
64 ConstrainedWindow* window_; 81 ConstrainedWindow* window_;
65 82
66 // Was the dialog closed from WebUI (in which case |html_delegate_|'s 83 // Was the dialog closed from WebUI (in which case |html_delegate_|'s
67 // OnDialogClosed() method has already been called)? 84 // OnDialogClosed() method has already been called)?
68 bool closed_via_webui_; 85 bool closed_via_webui_;
86
87 // If true, release |tab_| on close instead of destroying it.
88 bool release_tab_on_close_;
69 }; 89 };
70 90
71 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( 91 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk(
72 Profile* profile, 92 Profile* profile,
73 HtmlDialogUIDelegate* delegate) 93 HtmlDialogUIDelegate* delegate)
74 : HtmlDialogTabContentsDelegate(profile), 94 : HtmlDialogTabContentsDelegate(profile),
75 tab_(new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL)),
76 tab_contents_container_(NULL), 95 tab_contents_container_(NULL),
77 html_delegate_(delegate), 96 html_delegate_(delegate),
78 window_(NULL), 97 window_(NULL),
79 closed_via_webui_(false) { 98 closed_via_webui_(false),
80 tab_.tab_contents()->set_delegate(this); 99 release_tab_on_close_(false) {
100 TabContents* tab_contents =
101 new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL);
102 tab_.reset(new TabContentsWrapper(tab_contents));
103 tab_contents->set_delegate(this);
81 104
82 // Set |this| as a property on the tab contents so that the ConstrainedHtmlUI 105 // Set |this| as a property on the tab contents so that the ConstrainedHtmlUI
83 // can get a reference to |this|. 106 // can get a reference to |this|.
84 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( 107 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty(
85 tab_.tab_contents()->property_bag(), this); 108 tab_contents->property_bag(), this);
86 109
87 tab_.tab_contents()->controller().LoadURL( 110 tab_contents->controller().LoadURL(delegate->GetDialogContentURL(), GURL(),
88 delegate->GetDialogContentURL(), GURL(), PageTransition::START_PAGE, 111 PageTransition::START_PAGE, std::string());
89 std::string()); 112 tab_contents_container_.SetTab(tab_.get());
90 tab_contents_container_.SetTab(&tab_);
91 113
92 gfx::Size dialog_size; 114 gfx::Size dialog_size;
93 delegate->GetDialogSize(&dialog_size); 115 delegate->GetDialogSize(&dialog_size);
94 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_.widget()), 116 gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_.widget()),
95 dialog_size.width(), 117 dialog_size.width(),
96 dialog_size.height()); 118 dialog_size.height());
97 119
98 gtk_widget_show_all(GetWidgetRoot()); 120 gtk_widget_show_all(GetWidgetRoot());
99 } 121 }
100 122
101 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() {
102 }
103
104 HtmlDialogUIDelegate*
105 ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() {
106 return html_delegate_;
107 }
108
109 void ConstrainedHtmlDelegateGtk::OnDialogCloseFromWebUI() {
110 closed_via_webui_ = true;
111 window_->CloseConstrainedWindow();
112 }
113
114 // static 123 // static
115 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( 124 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
116 Profile* profile, 125 Profile* profile,
117 HtmlDialogUIDelegate* delegate, 126 HtmlDialogUIDelegate* delegate,
118 TabContentsWrapper* overshadowed) { 127 TabContentsWrapper* overshadowed) {
119 ConstrainedHtmlDelegateGtk* constrained_delegate = 128 ConstrainedHtmlDelegateGtk* constrained_delegate =
120 new ConstrainedHtmlDelegateGtk(profile, delegate); 129 new ConstrainedHtmlDelegateGtk(profile, delegate);
121 ConstrainedWindow* constrained_window = 130 ConstrainedWindow* constrained_window =
122 new ConstrainedWindowGtk(overshadowed, constrained_delegate); 131 new ConstrainedWindowGtk(overshadowed, constrained_delegate);
123 constrained_delegate->set_window(constrained_window); 132 constrained_delegate->set_window(constrained_window);
124 return constrained_window; 133 return constrained_window;
Evan Stade 2011/10/11 02:49:17 seems like you could just modify this to return th
Lei Zhang 2011/10/11 03:15:58 Do you really want me to change ConstrainedHtmlUID
Evan Stade 2011/10/11 22:54:59 yea I don't want the duplication and I don't like
Lei Zhang 2011/10/11 23:41:25 Done.
125 } 134 }
135
136 // static
137 TabContentsWrapper* ConstrainedHtmlUI::CreateConstrainedPrintPreviewHtmlUI(
138 Profile* profile,
139 HtmlDialogUIDelegate* delegate,
140 TabContentsWrapper* overshadowed) {
141 ConstrainedHtmlDelegateGtk* constrained_delegate =
142 new ConstrainedHtmlDelegateGtk(profile, delegate);
143 ConstrainedWindow* constrained_window =
144 new ConstrainedWindowGtk(overshadowed, constrained_delegate);
145 constrained_delegate->set_window(constrained_window);
146 return constrained_delegate->tab();
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698