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

Side by Side Diff: chrome/browser/ui/views/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/tab_contents/tab_contents_wrapper.h" 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" 10 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.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/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
14 #include "ui/base/gtk/gtk_hig_constants.h" 14 #include "ui/base/gtk/gtk_hig_constants.h"
15 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
16 #include "views/widget/native_widget_gtk.h" 16 #include "views/widget/native_widget_gtk.h"
17 17
18 // ConstrainedHtmlDelegateGtk works with ConstrainedWindowGtk to present 18 // ConstrainedHtmlDelegateGtk works with ConstrainedWindowGtk to present
19 // a TabContents in a ContraintedHtmlUI. 19 // a TabContents in a ContraintedHtmlUI.
20 class ConstrainedHtmlDelegateGtk : public views::NativeWidgetGtk, 20 class ConstrainedHtmlDelegateGtk : public views::NativeWidgetGtk,
21 public ConstrainedHtmlUIDelegate, 21 public ConstrainedHtmlUIDelegate,
22 public ConstrainedWindowGtkDelegate, 22 public ConstrainedWindowGtkDelegate,
23 public HtmlDialogTabContentsDelegate { 23 public HtmlDialogTabContentsDelegate {
24 public: 24 public:
25 ConstrainedHtmlDelegateGtk(Profile* profile, 25 ConstrainedHtmlDelegateGtk(Profile* profile,
26 HtmlDialogUIDelegate* delegate); 26 HtmlDialogUIDelegate* delegate);
27 ~ConstrainedHtmlDelegateGtk(); 27 ~ConstrainedHtmlDelegateGtk();
28 28
29 TabContentsWrapper* tab() {
30 return html_tab_contents_.get();
31 }
32
29 // ConstrainedHtmlUIDelegate interface. 33 // ConstrainedHtmlUIDelegate interface.
30 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; 34 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE;
31 virtual void OnDialogCloseFromWebUI() OVERRIDE; 35 virtual void OnDialogCloseFromWebUI() OVERRIDE;
32 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { 36 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE {
33 *color = ui::kGdkWhite; 37 release_tab_on_close_ = true;
34 return true;
35 } 38 }
36 39
37 // ConstrainedWindowGtkDelegate implementation. 40 // ConstrainedWindowGtkDelegate implementation.
38 virtual GtkWidget* GetWidgetRoot() OVERRIDE { 41 virtual GtkWidget* GetWidgetRoot() OVERRIDE {
39 return GetNativeView(); 42 return GetNativeView();
40 } 43 }
41 virtual GtkWidget* GetFocusWidget() OVERRIDE { 44 virtual GtkWidget* GetFocusWidget() OVERRIDE {
42 return html_tab_contents_.GetContentNativeView(); 45 return html_tab_contents_->tab_contents()->GetContentNativeView();
43 } 46 }
44 virtual void DeleteDelegate() OVERRIDE { 47 virtual void DeleteDelegate() OVERRIDE {
45 if (!closed_via_webui_) 48 if (!closed_via_webui_)
46 html_delegate_->OnDialogClosed(""); 49 html_delegate_->OnDialogClosed("");
47 tab_container_->ChangeTabContents(NULL); 50 tab_container_->ChangeTabContents(NULL);
48 } 51 }
52 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE {
53 *color = ui::kGdkWhite;
54 return true;
55 }
49 virtual bool ShouldHaveBorderPadding() const OVERRIDE { 56 virtual bool ShouldHaveBorderPadding() const OVERRIDE {
50 return false; 57 return false;
51 } 58 }
52 59
53 // HtmlDialogTabContentsDelegate interface. 60 // HtmlDialogTabContentsDelegate interface.
54 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE {} 61 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE {}
55 62
56 void set_window(ConstrainedWindow* window) { 63 void set_window(ConstrainedWindow* window) {
57 window_ = window; 64 window_ = window;
58 } 65 }
59 66
60 private: 67 private:
61 TabContents html_tab_contents_; 68 scoped_ptr<TabContentsWrapper> html_tab_contents_;
62 TabContentsContainer* tab_container_; 69 TabContentsContainer* tab_container_;
63 70
64 HtmlDialogUIDelegate* html_delegate_; 71 HtmlDialogUIDelegate* html_delegate_;
65 72
66 // The constrained window that owns |this|. Saved so we can close it later. 73 // The constrained window that owns |this|. Saved so we can close it later.
67 ConstrainedWindow* window_; 74 ConstrainedWindow* window_;
68 75
69 // Was the dialog closed from WebUI (in which case |html_delegate_|'s 76 // Was the dialog closed from WebUI (in which case |html_delegate_|'s
70 // OnDialogClosed() method has already been called)? 77 // OnDialogClosed() method has already been called)?
71 bool closed_via_webui_; 78 bool closed_via_webui_;
79
80 // If true, release |tab_| on close instead of destroying it.
81 bool release_tab_on_close_;
72 }; 82 };
73 83
74 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( 84 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk(
75 Profile* profile, 85 Profile* profile,
76 HtmlDialogUIDelegate* delegate) 86 HtmlDialogUIDelegate* delegate)
77 : views::NativeWidgetGtk(new views::Widget), 87 : views::NativeWidgetGtk(new views::Widget),
78 HtmlDialogTabContentsDelegate(profile), 88 HtmlDialogTabContentsDelegate(profile),
79 html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL),
80 tab_container_(NULL), 89 tab_container_(NULL),
81 html_delegate_(delegate), 90 html_delegate_(delegate),
82 window_(NULL), 91 window_(NULL),
83 closed_via_webui_(false) { 92 closed_via_webui_(false) {
84 CHECK(delegate); 93 CHECK(delegate);
85 html_tab_contents_.set_delegate(this); 94 TabContents* tab_contents =
95 new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL);
96 html_tab_contents_.reset(new TabContentsWrapper(tab_contents));
97 tab_contents->set_delegate(this);
86 98
87 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. 99 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it.
88 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( 100 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty(
89 html_tab_contents_.property_bag(), this); 101 tab_contents->property_bag(), this);
90 html_tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), 102 tab_contents->controller().LoadURL(delegate->GetDialogContentURL(), GURL(),
91 GURL(), 103 PageTransition::START_PAGE, std::string());
92 PageTransition::START_PAGE,
93 std::string());
94 104
95 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 105 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
96 params.native_widget = this; 106 params.native_widget = this;
97 GetWidget()->Init(params); 107 GetWidget()->Init(params);
98 108
99 tab_container_ = new TabContentsContainer; 109 tab_container_ = new TabContentsContainer;
100 GetWidget()->SetContentsView(tab_container_); 110 GetWidget()->SetContentsView(tab_container_);
101 tab_container_->ChangeTabContents(&html_tab_contents_); 111 tab_container_->ChangeTabContents(html_tab_contents_->tab_contents());
102 112
103 gfx::Size dialog_size; 113 gfx::Size dialog_size;
104 html_delegate_->GetDialogSize(&dialog_size); 114 html_delegate_->GetDialogSize(&dialog_size);
105 gtk_widget_set_size_request(GetWidgetRoot(), 115 gtk_widget_set_size_request(GetWidgetRoot(),
106 dialog_size.width(), 116 dialog_size.width(),
107 dialog_size.height()); 117 dialog_size.height());
108 } 118 }
109 119
110 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { 120 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() {
111 } 121 }
(...skipping 12 matching lines...) Expand all
124 Profile* profile, 134 Profile* profile,
125 HtmlDialogUIDelegate* delegate, 135 HtmlDialogUIDelegate* delegate,
126 TabContentsWrapper* wrapper) { 136 TabContentsWrapper* wrapper) {
127 ConstrainedHtmlDelegateGtk* constrained_delegate = 137 ConstrainedHtmlDelegateGtk* constrained_delegate =
128 new ConstrainedHtmlDelegateGtk(profile, delegate); 138 new ConstrainedHtmlDelegateGtk(profile, delegate);
129 ConstrainedWindow* constrained_window = 139 ConstrainedWindow* constrained_window =
130 new ConstrainedWindowGtk(wrapper, constrained_delegate); 140 new ConstrainedWindowGtk(wrapper, constrained_delegate);
131 constrained_delegate->set_window(constrained_window); 141 constrained_delegate->set_window(constrained_window);
132 return constrained_window; 142 return constrained_window;
133 } 143 }
144
145 // static
146 TabContentsWrapper* ConstrainedHtmlUI::CreateConstrainedPrintPreviewHtmlUI(
147 Profile* profile,
148 HtmlDialogUIDelegate* delegate,
149 TabContentsWrapper* wrapper) {
150 ConstrainedHtmlDelegateGtk* constrained_delegate =
151 new ConstrainedHtmlDelegateGtk(profile, delegate);
152 ConstrainedWindow* constrained_window =
153 new ConstrainedWindowGtk(wrapper, constrained_delegate);
154 constrained_delegate->set_window(constrained_window);
155 return constrained_delegate->tab();
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698