OLD | NEW |
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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 content::WebContents* initiator, | 27 content::WebContents* initiator, |
28 views::WebView* web_view) | 28 views::WebView* web_view) |
29 : ui::WebDialogWebContentsDelegate(browser_context, | 29 : ui::WebDialogWebContentsDelegate(browser_context, |
30 new ChromeWebContentsHandler()), | 30 new ChromeWebContentsHandler()), |
31 initiator_(initiator), | 31 initiator_(initiator), |
32 web_view_(web_view) { | 32 web_view_(web_view) { |
33 } | 33 } |
34 virtual ~WebDialogWebContentsDelegateViews() {} | 34 virtual ~WebDialogWebContentsDelegateViews() {} |
35 | 35 |
36 // ui::WebDialogWebContentsDelegate: | 36 // ui::WebDialogWebContentsDelegate: |
37 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE { | 37 virtual void WebContentsFocused(content::WebContents* contents) override { |
38 // Ensure the WebView is focused when its WebContents is focused. | 38 // Ensure the WebView is focused when its WebContents is focused. |
39 web_view_->RequestFocus(); | 39 web_view_->RequestFocus(); |
40 } | 40 } |
41 virtual void HandleKeyboardEvent( | 41 virtual void HandleKeyboardEvent( |
42 content::WebContents* source, | 42 content::WebContents* source, |
43 const content::NativeWebKeyboardEvent& event) OVERRIDE { | 43 const content::NativeWebKeyboardEvent& event) override { |
44 // Forward shortcut keys in dialog to the browser. http://crbug.com/104586 | 44 // Forward shortcut keys in dialog to the browser. http://crbug.com/104586 |
45 // Disabled on Mac due to http://crbug.com/112173 | 45 // Disabled on Mac due to http://crbug.com/112173 |
46 #if !defined(OS_MACOSX) | 46 #if !defined(OS_MACOSX) |
47 Browser* current_browser = chrome::FindBrowserWithWebContents(initiator_); | 47 Browser* current_browser = chrome::FindBrowserWithWebContents(initiator_); |
48 if (!current_browser) | 48 if (!current_browser) |
49 return; | 49 return; |
50 current_browser->window()->HandleKeyboardEvent(event); | 50 current_browser->window()->HandleKeyboardEvent(event); |
51 #endif | 51 #endif |
52 } | 52 } |
53 | 53 |
(...skipping 11 matching lines...) Expand all Loading... |
65 ui::WebDialogDelegate* delegate, | 65 ui::WebDialogDelegate* delegate, |
66 content::WebContents* web_contents, | 66 content::WebContents* web_contents, |
67 views::WebView* view) | 67 views::WebView* view) |
68 : ConstrainedWebDialogDelegateBase(context, delegate, | 68 : ConstrainedWebDialogDelegateBase(context, delegate, |
69 new WebDialogWebContentsDelegateViews(context, web_contents, view)), | 69 new WebDialogWebContentsDelegateViews(context, web_contents, view)), |
70 view_(view) {} | 70 view_(view) {} |
71 | 71 |
72 virtual ~ConstrainedWebDialogDelegateViews() {} | 72 virtual ~ConstrainedWebDialogDelegateViews() {} |
73 | 73 |
74 // ui::WebDialogWebContentsDelegate: | 74 // ui::WebDialogWebContentsDelegate: |
75 virtual void CloseContents(content::WebContents* source) OVERRIDE { | 75 virtual void CloseContents(content::WebContents* source) override { |
76 view_->GetWidget()->Close(); | 76 view_->GetWidget()->Close(); |
77 } | 77 } |
78 | 78 |
79 // contents::WebContentsDelegate: | 79 // contents::WebContentsDelegate: |
80 virtual void HandleKeyboardEvent( | 80 virtual void HandleKeyboardEvent( |
81 content::WebContents* source, | 81 content::WebContents* source, |
82 const content::NativeWebKeyboardEvent& event) OVERRIDE { | 82 const content::NativeWebKeyboardEvent& event) override { |
83 unhandled_keyboard_event_handler_.HandleKeyboardEvent( | 83 unhandled_keyboard_event_handler_.HandleKeyboardEvent( |
84 event, view_->GetFocusManager()); | 84 event, view_->GetFocusManager()); |
85 } | 85 } |
86 | 86 |
87 // ConstrainedWebDialogDelegate: | 87 // ConstrainedWebDialogDelegate: |
88 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { | 88 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() override { |
89 return view_->GetWidget()->GetNativeView(); | 89 return view_->GetWidget()->GetNativeView(); |
90 } | 90 } |
91 | 91 |
92 private: | 92 private: |
93 // Converts keyboard events on the WebContents to accelerators. | 93 // Converts keyboard events on the WebContents to accelerators. |
94 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 94 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
95 | 95 |
96 views::WebView* view_; | 96 views::WebView* view_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); | 98 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); |
(...skipping 10 matching lines...) Expand all Loading... |
109 content::WebContents* web_contents) | 109 content::WebContents* web_contents) |
110 : views::WebView(browser_context), | 110 : views::WebView(browser_context), |
111 impl_(new ConstrainedWebDialogDelegateViews(browser_context, delegate, | 111 impl_(new ConstrainedWebDialogDelegateViews(browser_context, delegate, |
112 web_contents, this)) { | 112 web_contents, this)) { |
113 SetWebContents(GetWebContents()); | 113 SetWebContents(GetWebContents()); |
114 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 114 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
115 } | 115 } |
116 virtual ~ConstrainedWebDialogDelegateViewViews() {} | 116 virtual ~ConstrainedWebDialogDelegateViewViews() {} |
117 | 117 |
118 // ConstrainedWebDialogDelegate: | 118 // ConstrainedWebDialogDelegate: |
119 virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const OVERRIDE { | 119 virtual const ui::WebDialogDelegate* GetWebDialogDelegate() const override { |
120 return impl_->GetWebDialogDelegate(); | 120 return impl_->GetWebDialogDelegate(); |
121 } | 121 } |
122 virtual ui::WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { | 122 virtual ui::WebDialogDelegate* GetWebDialogDelegate() override { |
123 return impl_->GetWebDialogDelegate(); | 123 return impl_->GetWebDialogDelegate(); |
124 } | 124 } |
125 virtual void OnDialogCloseFromWebUI() OVERRIDE { | 125 virtual void OnDialogCloseFromWebUI() override { |
126 return impl_->OnDialogCloseFromWebUI(); | 126 return impl_->OnDialogCloseFromWebUI(); |
127 } | 127 } |
128 virtual void ReleaseWebContentsOnDialogClose() OVERRIDE { | 128 virtual void ReleaseWebContentsOnDialogClose() override { |
129 return impl_->ReleaseWebContentsOnDialogClose(); | 129 return impl_->ReleaseWebContentsOnDialogClose(); |
130 } | 130 } |
131 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() OVERRIDE { | 131 virtual web_modal::NativeWebContentsModalDialog GetNativeDialog() override { |
132 return impl_->GetNativeDialog(); | 132 return impl_->GetNativeDialog(); |
133 } | 133 } |
134 virtual content::WebContents* GetWebContents() OVERRIDE { | 134 virtual content::WebContents* GetWebContents() override { |
135 return impl_->GetWebContents(); | 135 return impl_->GetWebContents(); |
136 } | 136 } |
137 | 137 |
138 // views::WidgetDelegate: | 138 // views::WidgetDelegate: |
139 virtual views::View* GetInitiallyFocusedView() OVERRIDE { | 139 virtual views::View* GetInitiallyFocusedView() override { |
140 return this; | 140 return this; |
141 } | 141 } |
142 virtual void WindowClosing() OVERRIDE { | 142 virtual void WindowClosing() override { |
143 if (!impl_->closed_via_webui()) | 143 if (!impl_->closed_via_webui()) |
144 GetWebDialogDelegate()->OnDialogClosed(std::string()); | 144 GetWebDialogDelegate()->OnDialogClosed(std::string()); |
145 } | 145 } |
146 virtual views::Widget* GetWidget() OVERRIDE { | 146 virtual views::Widget* GetWidget() override { |
147 return View::GetWidget(); | 147 return View::GetWidget(); |
148 } | 148 } |
149 virtual const views::Widget* GetWidget() const OVERRIDE { | 149 virtual const views::Widget* GetWidget() const override { |
150 return View::GetWidget(); | 150 return View::GetWidget(); |
151 } | 151 } |
152 virtual base::string16 GetWindowTitle() const OVERRIDE { | 152 virtual base::string16 GetWindowTitle() const override { |
153 return impl_->closed_via_webui() ? base::string16() : | 153 return impl_->closed_via_webui() ? base::string16() : |
154 GetWebDialogDelegate()->GetDialogTitle(); | 154 GetWebDialogDelegate()->GetDialogTitle(); |
155 } | 155 } |
156 virtual views::View* GetContentsView() OVERRIDE { | 156 virtual views::View* GetContentsView() override { |
157 return this; | 157 return this; |
158 } | 158 } |
159 virtual views::NonClientFrameView* CreateNonClientFrameView( | 159 virtual views::NonClientFrameView* CreateNonClientFrameView( |
160 views::Widget* widget) OVERRIDE { | 160 views::Widget* widget) override { |
161 return views::DialogDelegate::CreateDialogFrameView(widget); | 161 return views::DialogDelegate::CreateDialogFrameView(widget); |
162 } | 162 } |
163 virtual bool ShouldShowCloseButton() const OVERRIDE { | 163 virtual bool ShouldShowCloseButton() const override { |
164 // No close button if the dialog doesn't want a title bar. | 164 // No close button if the dialog doesn't want a title bar. |
165 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle(); | 165 return impl_->GetWebDialogDelegate()->ShouldShowDialogTitle(); |
166 } | 166 } |
167 virtual ui::ModalType GetModalType() const OVERRIDE { | 167 virtual ui::ModalType GetModalType() const override { |
168 return ui::MODAL_TYPE_CHILD; | 168 return ui::MODAL_TYPE_CHILD; |
169 } | 169 } |
170 | 170 |
171 // views::WebView: | 171 // views::WebView: |
172 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | 172 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override { |
173 // Pressing ESC closes the dialog. | 173 // Pressing ESC closes the dialog. |
174 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 174 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
175 GetWidget()->Close(); | 175 GetWidget()->Close(); |
176 return true; | 176 return true; |
177 } | 177 } |
178 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 178 virtual gfx::Size GetPreferredSize() const override { |
179 gfx::Size size; | 179 gfx::Size size; |
180 if (!impl_->closed_via_webui()) | 180 if (!impl_->closed_via_webui()) |
181 GetWebDialogDelegate()->GetDialogSize(&size); | 181 GetWebDialogDelegate()->GetDialogSize(&size); |
182 return size; | 182 return size; |
183 } | 183 } |
184 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 184 virtual gfx::Size GetMinimumSize() const override { |
185 // Return an empty size so that we can be made smaller. | 185 // Return an empty size so that we can be made smaller. |
186 return gfx::Size(); | 186 return gfx::Size(); |
187 } | 187 } |
188 | 188 |
189 private: | 189 private: |
190 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; | 190 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; |
191 | 191 |
192 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); | 192 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); |
193 }; | 193 }; |
194 | 194 |
195 } // namespace | 195 } // namespace |
196 | 196 |
197 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 197 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
198 content::BrowserContext* browser_context, | 198 content::BrowserContext* browser_context, |
199 ui::WebDialogDelegate* delegate, | 199 ui::WebDialogDelegate* delegate, |
200 content::WebContents* web_contents) { | 200 content::WebContents* web_contents) { |
201 ConstrainedWebDialogDelegateViewViews* dialog = | 201 ConstrainedWebDialogDelegateViewViews* dialog = |
202 new ConstrainedWebDialogDelegateViewViews( | 202 new ConstrainedWebDialogDelegateViewViews( |
203 browser_context, delegate, web_contents); | 203 browser_context, delegate, web_contents); |
204 ShowWebModalDialogViews(dialog, web_contents); | 204 ShowWebModalDialogViews(dialog, web_contents); |
205 return dialog; | 205 return dialog; |
206 } | 206 } |
OLD | NEW |