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

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

Issue 10446076: Handle Escape key on constrained window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 8 years, 6 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
« no previous file with comments | « chrome/browser/resources/certificate_viewer.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.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/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "content/public/browser/native_web_keyboard_event.h"
11 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
12 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
13 #include "ui/views/controls/webview/webview.h" 14 #include "ui/views/controls/webview/webview.h"
14 #include "ui/views/view.h" 15 #include "ui/views/view.h"
16 #include "ui/views/widget/native_widget_aura.h"
sky 2012/05/31 21:38:23 This should only be included for aura too.
yoshiki 2012/06/18 15:45:32 Done.
15 #include "ui/views/widget/widget_delegate.h" 17 #include "ui/views/widget/widget_delegate.h"
16 #include "ui/web_dialogs/web_dialog_delegate.h" 18 #include "ui/web_dialogs/web_dialog_delegate.h"
17 #include "ui/web_dialogs/web_dialog_ui.h" 19 #include "ui/web_dialogs/web_dialog_ui.h"
18 20
21 #if defined(USE_AURA)
22 #include "ui/aura/event.h"
23 #include "ui/aura/window.h"
24 #endif // defined(USE_AURA)
sky 2012/05/31 21:38:23 remove the trailing //
yoshiki 2012/06/18 15:45:32 Done.
25
19 using content::WebContents; 26 using content::WebContents;
20 using ui::ConstrainedWebDialogDelegate; 27 using ui::ConstrainedWebDialogDelegate;
21 using ui::ConstrainedWebDialogUI; 28 using ui::ConstrainedWebDialogUI;
22 using ui::WebDialogDelegate; 29 using ui::WebDialogDelegate;
23 30
24 namespace { 31 namespace {
25 32
26 class ConstrainedWebDialogDelegateViews 33 class ConstrainedWebDialogDelegateViews
27 : public ConstrainedWebDialogDelegateBase { 34 : public ConstrainedWebDialogDelegateBase {
28 public: 35 public:
(...skipping 11 matching lines...) Expand all
40 } 47 }
41 } 48 }
42 49
43 virtual ~ConstrainedWebDialogDelegateViews() {} 50 virtual ~ConstrainedWebDialogDelegateViews() {}
44 51
45 // WebDialogWebContentsDelegate interface. 52 // WebDialogWebContentsDelegate interface.
46 virtual void CloseContents(WebContents* source) OVERRIDE { 53 virtual void CloseContents(WebContents* source) OVERRIDE {
47 window()->CloseConstrainedWindow(); 54 window()->CloseConstrainedWindow();
48 } 55 }
49 56
57 // contents::WebContentsDelegate
58 virtual void HandleKeyboardEvent(
59 const content::NativeWebKeyboardEvent& event) OVERRIDE {
60 #if defined(USE_AURA)
sky 2012/05/31 21:38:23 Can you use unhandled_keyboard_event_handler for t
yoshiki 2012/06/18 15:45:32 Done.
61 aura::KeyEvent aura_event(event.os_event->native_event(), false);
62 window()->GetNativeWindow()->delegate()->OnKeyEvent(&aura_event);
63 #elif defined(OS_WIN)
64 // TODO(yoshiki): Fill this when this is necessary.
65 NOTIMPLEMENTED();
66 #endif
67 }
68
50 private: 69 private:
51 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); 70 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews);
52 }; 71 };
53 72
54 } // namespace 73 } // namespace
55 74
56 class ConstrainedWebDialogDelegateViewViews 75 class ConstrainedWebDialogDelegateViewViews
57 : public views::WebView, 76 : public views::WebView,
58 public ConstrainedWebDialogDelegate, 77 public ConstrainedWebDialogDelegate,
59 public views::WidgetDelegate { 78 public views::WidgetDelegate {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 125 }
107 virtual string16 GetWindowTitle() const OVERRIDE { 126 virtual string16 GetWindowTitle() const OVERRIDE {
108 return impl_->closed_via_webui() ? string16() : 127 return impl_->closed_via_webui() ? string16() :
109 GetWebDialogDelegate()->GetDialogTitle(); 128 GetWebDialogDelegate()->GetDialogTitle();
110 } 129 }
111 virtual views::View* GetContentsView() OVERRIDE { 130 virtual views::View* GetContentsView() OVERRIDE {
112 return this; 131 return this;
113 } 132 }
114 133
115 // views::WebView overrides. 134 // views::WebView overrides.
135 virtual bool AcceleratorPressed(
136 const ui::Accelerator& accelerator) OVERRIDE {
137 // Pressing ESC closes the dialog.
138 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
139 window()->CloseConstrainedWindow();
140 return true;
141 }
116 virtual gfx::Size GetPreferredSize() OVERRIDE { 142 virtual gfx::Size GetPreferredSize() OVERRIDE {
117 gfx::Size size; 143 gfx::Size size;
118 if (!impl_->closed_via_webui()) 144 if (!impl_->closed_via_webui())
119 GetWebDialogDelegate()->GetDialogSize(&size); 145 GetWebDialogDelegate()->GetDialogSize(&size);
120 return size; 146 return size;
121 } 147 }
122 148
123 private: 149 private:
124 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; 150 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_;
125 151
126 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); 152 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
127 }; 153 };
128 154
129 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews( 155 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews(
130 Profile* profile, 156 Profile* profile,
131 WebDialogDelegate* delegate, 157 WebDialogDelegate* delegate,
132 WebDialogWebContentsDelegate* tab_delegate) 158 WebDialogWebContentsDelegate* tab_delegate)
133 : views::WebView(profile), 159 : views::WebView(profile),
134 impl_(new ConstrainedWebDialogDelegateViews(profile, 160 impl_(new ConstrainedWebDialogDelegateViews(profile,
135 delegate, 161 delegate,
136 tab_delegate)) { 162 tab_delegate)) {
137 SetWebContents(tab()->web_contents()); 163 SetWebContents(tab()->web_contents());
164
165 // Pressing ESC closes the dialog.
166 set_allow_accelerators(true);
167 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
138 } 168 }
139 169
140 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() { 170 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() {
141 } 171 }
142 172
143 ConstrainedWebDialogDelegate* ui::CreateConstrainedWebDialog( 173 ConstrainedWebDialogDelegate* ui::CreateConstrainedWebDialog(
144 Profile* profile, 174 Profile* profile,
145 WebDialogDelegate* delegate, 175 WebDialogDelegate* delegate,
146 WebDialogWebContentsDelegate* tab_delegate, 176 WebDialogWebContentsDelegate* tab_delegate,
147 TabContentsWrapper* container) { 177 TabContentsWrapper* container) {
148 ConstrainedWebDialogDelegateViewViews* constrained_delegate = 178 ConstrainedWebDialogDelegateViewViews* constrained_delegate =
149 new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate) ; 179 new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate) ;
150 ConstrainedWindow* constrained_window = 180 ConstrainedWindow* constrained_window =
151 new ConstrainedWindowViews(container, constrained_delegate); 181 new ConstrainedWindowViews(container, constrained_delegate);
152 constrained_delegate->set_window(constrained_window); 182 constrained_delegate->set_window(constrained_window);
153 return constrained_delegate; 183 return constrained_delegate;
154 } 184 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/certificate_viewer.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698