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

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

Issue 12276010: Factor out uses of the WebContentsModalDialog interface from platform-independent code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove incorrect override Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 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 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_web_dialog_delegate_base.h" 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/constrained_window_views.h" 8 #include "chrome/browser/ui/views/constrained_window_views.h"
9 #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" 9 #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h"
10 #include "content/public/browser/native_web_keyboard_event.h" 10 #include "content/public/browser/native_web_keyboard_event.h"
(...skipping 20 matching lines...) Expand all
31 WebDialogWebContentsDelegate* tab_delegate, 31 WebDialogWebContentsDelegate* tab_delegate,
32 views::WebView* view) 32 views::WebView* view)
33 : ConstrainedWebDialogDelegateBase( 33 : ConstrainedWebDialogDelegateBase(
34 browser_context, delegate, tab_delegate), 34 browser_context, delegate, tab_delegate),
35 view_(view) {} 35 view_(view) {}
36 36
37 virtual ~ConstrainedWebDialogDelegateViews() {} 37 virtual ~ConstrainedWebDialogDelegateViews() {}
38 38
39 // WebDialogWebContentsDelegate interface. 39 // WebDialogWebContentsDelegate interface.
40 virtual void CloseContents(WebContents* source) OVERRIDE { 40 virtual void CloseContents(WebContents* source) OVERRIDE {
41 GetWindow()->CloseWebContentsModalDialog(); 41 window_->CloseWebContentsModalDialog();
42 } 42 }
43 43
44 // contents::WebContentsDelegate 44 // contents::WebContentsDelegate
45 virtual void HandleKeyboardEvent( 45 virtual void HandleKeyboardEvent(
46 content::WebContents* source, 46 content::WebContents* source,
47 const content::NativeWebKeyboardEvent& event) OVERRIDE { 47 const content::NativeWebKeyboardEvent& event) OVERRIDE {
48 unhandled_keyboard_event_handler_.HandleKeyboardEvent( 48 unhandled_keyboard_event_handler_.HandleKeyboardEvent(
49 event, view_->GetFocusManager()); 49 event, view_->GetFocusManager());
50 } 50 }
51 51
52 // ConstrainedWebDialogDelegate
53 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE {
54 return window_->GetNativeView();
55 }
56
57 void set_window(ConstrainedWindowViews* window) { window_ = window; }
58 ConstrainedWindowViews* window() const { return window_; }
59
52 private: 60 private:
53 // Converts keyboard events on the WebContents to accelerators. 61 // Converts keyboard events on the WebContents to accelerators.
54 UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; 62 UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
55 63
56 views::WebView* view_; 64 views::WebView* view_;
65 ConstrainedWindowViews* window_;
57 66
58 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); 67 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews);
59 }; 68 };
60 69
61 } // namespace 70 } // namespace
62 71
63 class ConstrainedWebDialogDelegateViewViews 72 class ConstrainedWebDialogDelegateViewViews
64 : public views::WebView, 73 : public views::WebView,
65 public ConstrainedWebDialogDelegate, 74 public ConstrainedWebDialogDelegate,
66 public views::WidgetDelegate { 75 public views::WidgetDelegate {
67 public: 76 public:
68 ConstrainedWebDialogDelegateViewViews( 77 ConstrainedWebDialogDelegateViewViews(
69 content::BrowserContext* browser_context, 78 content::BrowserContext* browser_context,
70 WebDialogDelegate* delegate, 79 WebDialogDelegate* delegate,
71 WebDialogWebContentsDelegate* tab_delegate); 80 WebDialogWebContentsDelegate* tab_delegate);
72 virtual ~ConstrainedWebDialogDelegateViewViews(); 81 virtual ~ConstrainedWebDialogDelegateViewViews();
73 82
74 void set_window(WebContentsModalDialog* window) {
75 return impl_->set_window(window);
76 }
77
78 // ConstrainedWebDialogDelegate interface 83 // ConstrainedWebDialogDelegate interface
79 virtual const WebDialogDelegate* 84 virtual const WebDialogDelegate*
80 GetWebDialogDelegate() const OVERRIDE { 85 GetWebDialogDelegate() const OVERRIDE {
81 return impl_->GetWebDialogDelegate(); 86 return impl_->GetWebDialogDelegate();
82 } 87 }
83 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { 88 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE {
84 return impl_->GetWebDialogDelegate(); 89 return impl_->GetWebDialogDelegate();
85 } 90 }
86 virtual void OnDialogCloseFromWebUI() OVERRIDE { 91 virtual void OnDialogCloseFromWebUI() OVERRIDE {
87 return impl_->OnDialogCloseFromWebUI(); 92 return impl_->OnDialogCloseFromWebUI();
88 } 93 }
89 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { 94 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE {
90 return impl_->ReleaseWebContentsOnDialogClose(); 95 return impl_->ReleaseWebContentsOnDialogClose();
91 } 96 }
92 virtual WebContentsModalDialog* GetWindow() OVERRIDE { 97 virtual NativeWebContentsModalDialog GetNativeDialog() OVERRIDE {
93 return impl_->GetWindow(); 98 return impl_->window()->GetNativeDialog();
94 } 99 }
95 virtual WebContents* GetWebContents() OVERRIDE { 100 virtual WebContents* GetWebContents() OVERRIDE {
96 return impl_->GetWebContents(); 101 return impl_->GetWebContents();
97 } 102 }
98 103
99 // views::WidgetDelegate interface. 104 // views::WidgetDelegate interface.
100 virtual views::View* GetInitiallyFocusedView() OVERRIDE { 105 virtual views::View* GetInitiallyFocusedView() OVERRIDE {
101 return this; 106 return this;
102 } 107 }
103 virtual bool CanResize() const OVERRIDE { return true; } 108 virtual bool CanResize() const OVERRIDE { return true; }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 GetWidget()->CenterWindow( 141 GetWidget()->CenterWindow(
137 GetWidget()->non_client_view()->GetPreferredSize()); 142 GetWidget()->non_client_view()->GetPreferredSize());
138 views::WidgetDelegate::OnWidgetMove(); 143 views::WidgetDelegate::OnWidgetMove();
139 } 144 }
140 145
141 // views::WebView overrides. 146 // views::WebView overrides.
142 virtual bool AcceleratorPressed( 147 virtual bool AcceleratorPressed(
143 const ui::Accelerator& accelerator) OVERRIDE { 148 const ui::Accelerator& accelerator) OVERRIDE {
144 // Pressing ESC closes the dialog. 149 // Pressing ESC closes the dialog.
145 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 150 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
146 GetWindow()->CloseWebContentsModalDialog(); 151 impl_->window()->CloseWebContentsModalDialog();
147 return true; 152 return true;
148 } 153 }
149 virtual gfx::Size GetPreferredSize() OVERRIDE { 154 virtual gfx::Size GetPreferredSize() OVERRIDE {
150 gfx::Size size; 155 gfx::Size size;
151 if (!impl_->closed_via_webui()) 156 if (!impl_->closed_via_webui())
152 GetWebDialogDelegate()->GetDialogSize(&size); 157 GetWebDialogDelegate()->GetDialogSize(&size);
153 return size; 158 return size;
154 } 159 }
155 virtual gfx::Size GetMinimumSize() OVERRIDE { 160 virtual gfx::Size GetMinimumSize() OVERRIDE {
156 // Return an empty size so that we can be made smaller. 161 // Return an empty size so that we can be made smaller.
157 return gfx::Size(); 162 return gfx::Size();
158 } 163 }
159 164
160 private: 165 void SetWindow(ConstrainedWindowViews* window) {
166 impl_->set_window(window);
167 }
168
169 ConstrainedWindowViews* GetWindow() {
170 return impl_->window();
171 }
172
161 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; 173 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_;
162 174
163 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); 175 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
164 }; 176 };
165 177
166 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews( 178 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews(
167 content::BrowserContext* browser_context, 179 content::BrowserContext* browser_context,
168 WebDialogDelegate* delegate, 180 WebDialogDelegate* delegate,
169 WebDialogWebContentsDelegate* tab_delegate) 181 WebDialogWebContentsDelegate* tab_delegate)
170 : views::WebView(browser_context), 182 : views::WebView(browser_context),
(...skipping 11 matching lines...) Expand all
182 } 194 }
183 195
184 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( 196 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog(
185 content::BrowserContext* browser_context, 197 content::BrowserContext* browser_context,
186 WebDialogDelegate* delegate, 198 WebDialogDelegate* delegate,
187 WebDialogWebContentsDelegate* tab_delegate, 199 WebDialogWebContentsDelegate* tab_delegate,
188 content::WebContents* web_contents) { 200 content::WebContents* web_contents) {
189 ConstrainedWebDialogDelegateViewViews* constrained_delegate = 201 ConstrainedWebDialogDelegateViewViews* constrained_delegate =
190 new ConstrainedWebDialogDelegateViewViews( 202 new ConstrainedWebDialogDelegateViewViews(
191 browser_context, delegate, tab_delegate); 203 browser_context, delegate, tab_delegate);
192 WebContentsModalDialog* web_contents_modal_dialog = 204 ConstrainedWindowViews* window =
193 ConstrainedWindowViews::Create(web_contents, constrained_delegate); 205 ConstrainedWindowViews::Create(web_contents, constrained_delegate);
194 constrained_delegate->set_window(web_contents_modal_dialog); 206 constrained_delegate->SetWindow(window);
195 return constrained_delegate; 207 return constrained_delegate;
196 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698