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

Side by Side Diff: chrome/browser/ui/views/constrained_html_delegate_views.cc

Issue 10214001: WebDialogs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/constrained_html_ui_delegate_impl.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/browser/ui/views/constrained_window_views.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/html_dialog_ui.h"
12 #include "content/public/browser/web_contents.h"
13 #include "ui/gfx/size.h"
14 #include "ui/views/controls/webview/webview.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget_delegate.h"
17
18 using content::WebContents;
19
20 namespace {
21
22 class ConstrainedHtmlUIDelegateImplViews
23 : public ConstrainedHtmlUIDelegateImpl {
24 public:
25 ConstrainedHtmlUIDelegateImplViews(
26 Profile* profile,
27 HtmlDialogUIDelegate* delegate,
28 HtmlDialogTabContentsDelegate* tab_delegate)
29 : ConstrainedHtmlUIDelegateImpl(profile, delegate, tab_delegate) {
30 WebContents* web_contents = tab()->web_contents();
31 if (tab_delegate) {
32 set_override_tab_delegate(tab_delegate);
33 web_contents->SetDelegate(tab_delegate);
34 } else {
35 web_contents->SetDelegate(this);
36 }
37 }
38
39 virtual ~ConstrainedHtmlUIDelegateImplViews() {}
40
41 // HtmlDialogTabContentsDelegate interface.
42 virtual void CloseContents(WebContents* source) OVERRIDE {
43 window()->CloseConstrainedWindow();
44 }
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlUIDelegateImplViews);
48 };
49
50 } // namespace
51
52 class ConstrainedHtmlDelegateViews : public views::WebView,
53 public ConstrainedHtmlUIDelegate,
54 public views::WidgetDelegate {
55 public:
56 ConstrainedHtmlDelegateViews(Profile* profile,
57 HtmlDialogUIDelegate* delegate,
58 HtmlDialogTabContentsDelegate* tab_delegate);
59 virtual ~ConstrainedHtmlDelegateViews();
60
61 void set_window(ConstrainedWindow* window) {
62 return impl_->set_window(window);
63 }
64
65 // ConstrainedHtmlUIDelegate interface
66 virtual const HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() const OVERRIDE {
67 return impl_->GetHtmlDialogUIDelegate();
68 }
69 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE {
70 return impl_->GetHtmlDialogUIDelegate();
71 }
72 virtual void OnDialogCloseFromWebUI() OVERRIDE {
73 return impl_->OnDialogCloseFromWebUI();
74 }
75 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE {
76 return impl_->ReleaseTabContentsOnDialogClose();
77 }
78 virtual ConstrainedWindow* window() OVERRIDE {
79 return impl_->window();
80 }
81 virtual TabContentsWrapper* tab() OVERRIDE {
82 return impl_->tab();
83 }
84
85 // views::WidgetDelegate interface.
86 virtual views::View* GetInitiallyFocusedView() OVERRIDE {
87 return this;
88 }
89 virtual bool CanResize() const OVERRIDE { return true; }
90 virtual void WindowClosing() OVERRIDE {
91 if (!impl_->closed_via_webui())
92 GetHtmlDialogUIDelegate()->OnDialogClosed(std::string());
93 }
94 virtual views::Widget* GetWidget() OVERRIDE {
95 return View::GetWidget();
96 }
97 virtual const views::Widget* GetWidget() const OVERRIDE {
98 return View::GetWidget();
99 }
100 virtual string16 GetWindowTitle() const OVERRIDE {
101 return GetHtmlDialogUIDelegate()->GetDialogTitle();
102 }
103 virtual views::View* GetContentsView() OVERRIDE {
104 return this;
105 }
106
107 // views::WebView overrides.
108 virtual gfx::Size GetPreferredSize() OVERRIDE {
109 gfx::Size size;
110 GetHtmlDialogUIDelegate()->GetDialogSize(&size);
111 return size;
112 }
113
114 private:
115 scoped_ptr<ConstrainedHtmlUIDelegateImplViews> impl_;
116
117 DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlDelegateViews);
118 };
119
120 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews(
121 Profile* profile,
122 HtmlDialogUIDelegate* delegate,
123 HtmlDialogTabContentsDelegate* tab_delegate)
124 : views::WebView(profile),
125 impl_(new ConstrainedHtmlUIDelegateImplViews(profile,
126 delegate,
127 tab_delegate)) {
128 SetWebContents(tab()->web_contents());
129 }
130
131 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() {
132 }
133
134 // static
135 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
136 Profile* profile,
137 HtmlDialogUIDelegate* delegate,
138 HtmlDialogTabContentsDelegate* tab_delegate,
139 TabContentsWrapper* container) {
140 ConstrainedHtmlDelegateViews* constrained_delegate =
141 new ConstrainedHtmlDelegateViews(profile, delegate, tab_delegate);
142 ConstrainedWindow* constrained_window =
143 new ConstrainedWindowViews(container, constrained_delegate);
144 constrained_delegate->set_window(constrained_window);
145 return constrained_delegate;
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698