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

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/print_preview/print_preview.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 "chrome/browser/ui/webui/web_dialog_delegate.h" 11 #include "chrome/browser/ui/webui/web_dialog_delegate.h"
12 #include "chrome/browser/ui/webui/web_dialog_ui.h" 12 #include "chrome/browser/ui/webui/web_dialog_ui.h"
13 #include "content/public/browser/native_web_keyboard_event.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "ui/aura/event.h"
sky 2012/05/30 14:59:48 Only include aura if aura is defined.
yoshiki 2012/05/31 18:50:40 Done.
16 #include "ui/aura/window.h"
14 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
15 #include "ui/views/controls/webview/webview.h" 18 #include "ui/views/controls/webview/webview.h"
16 #include "ui/views/view.h" 19 #include "ui/views/view.h"
20 #include "ui/views/widget/native_widget_aura.h"
17 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
18 22
19 using content::WebContents; 23 using content::WebContents;
20 24
21 namespace { 25 namespace {
22 26
23 class ConstrainedWebDialogDelegateViews 27 class ConstrainedWebDialogDelegateViews
24 : public ConstrainedWebDialogDelegateBase { 28 : public ConstrainedWebDialogDelegateBase {
25 public: 29 public:
26 ConstrainedWebDialogDelegateViews( 30 ConstrainedWebDialogDelegateViews(
(...skipping 10 matching lines...) Expand all
37 } 41 }
38 } 42 }
39 43
40 virtual ~ConstrainedWebDialogDelegateViews() {} 44 virtual ~ConstrainedWebDialogDelegateViews() {}
41 45
42 // WebDialogWebContentsDelegate interface. 46 // WebDialogWebContentsDelegate interface.
43 virtual void CloseContents(WebContents* source) OVERRIDE { 47 virtual void CloseContents(WebContents* source) OVERRIDE {
44 window()->CloseConstrainedWindow(); 48 window()->CloseConstrainedWindow();
45 } 49 }
46 50
51 // contents::WebContentsDelegate
52 virtual void HandleKeyboardEvent(
53 const content::NativeWebKeyboardEvent& event) OVERRIDE {
54 #if defined(USE_AURA)
55 aura::KeyEvent aura_event(event.os_event->native_event(), false);
56 window()->GetNativeWindow()->delegate()->OnKeyEvent(&aura_event);
57 #elif defined(OS_WIN)
58 // TODO(yoshiki): Fill this when this is necessary.
59 NOTIMPLEMENTED();
60 #endif
61 }
62
47 private: 63 private:
48 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); 64 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews);
49 }; 65 };
50 66
51 } // namespace 67 } // namespace
52 68
53 class ConstrainedWebDialogDelegateViewViews 69 class ConstrainedWebDialogDelegateViewViews
54 : public views::WebView, 70 : public views::WebView,
55 public ConstrainedWebDialogDelegate, 71 public ConstrainedWebDialogDelegate,
56 public views::WidgetDelegate { 72 public views::WidgetDelegate {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 119 }
104 virtual string16 GetWindowTitle() const OVERRIDE { 120 virtual string16 GetWindowTitle() const OVERRIDE {
105 return impl_->closed_via_webui() ? string16() : 121 return impl_->closed_via_webui() ? string16() :
106 GetWebDialogDelegate()->GetDialogTitle(); 122 GetWebDialogDelegate()->GetDialogTitle();
107 } 123 }
108 virtual views::View* GetContentsView() OVERRIDE { 124 virtual views::View* GetContentsView() OVERRIDE {
109 return this; 125 return this;
110 } 126 }
111 127
112 // views::WebView overrides. 128 // views::WebView overrides.
129 virtual bool AcceleratorPressed(
130 const ui::Accelerator& accelerator) OVERRIDE {
131 // Pressing ESC closes the dialog.
132 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
133 if (GetWidget())
134 GetWidget()->Close();
sky 2012/05/30 14:59:48 Don't you need to route this to CloseConstrainedWi
yoshiki 2012/05/31 18:50:40 Done.
135 return true;
136 }
113 virtual gfx::Size GetPreferredSize() OVERRIDE { 137 virtual gfx::Size GetPreferredSize() OVERRIDE {
114 gfx::Size size; 138 gfx::Size size;
115 if (!impl_->closed_via_webui()) 139 if (!impl_->closed_via_webui())
116 GetWebDialogDelegate()->GetDialogSize(&size); 140 GetWebDialogDelegate()->GetDialogSize(&size);
117 return size; 141 return size;
118 } 142 }
119 143
120 private: 144 private:
121 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; 145 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_;
122 146
123 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); 147 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews);
124 }; 148 };
125 149
126 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews( 150 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews(
127 Profile* profile, 151 Profile* profile,
128 WebDialogDelegate* delegate, 152 WebDialogDelegate* delegate,
129 WebDialogWebContentsDelegate* tab_delegate) 153 WebDialogWebContentsDelegate* tab_delegate)
130 : views::WebView(profile), 154 : views::WebView(profile),
131 impl_(new ConstrainedWebDialogDelegateViews(profile, 155 impl_(new ConstrainedWebDialogDelegateViews(profile,
132 delegate, 156 delegate,
133 tab_delegate)) { 157 tab_delegate)) {
134 SetWebContents(tab()->web_contents()); 158 SetWebContents(tab()->web_contents());
159
160 // Pressing ESC closes the dialog.
161 set_allow_accelerators(true);
162 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
135 } 163 }
136 164
137 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() { 165 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() {
138 } 166 }
139 167
140 // static 168 // static
141 ConstrainedWebDialogDelegate* 169 ConstrainedWebDialogDelegate*
142 ConstrainedWebDialogUI::CreateConstrainedWebDialog( 170 ConstrainedWebDialogUI::CreateConstrainedWebDialog(
143 Profile* profile, 171 Profile* profile,
144 WebDialogDelegate* delegate, 172 WebDialogDelegate* delegate,
145 WebDialogWebContentsDelegate* tab_delegate, 173 WebDialogWebContentsDelegate* tab_delegate,
146 TabContentsWrapper* container) { 174 TabContentsWrapper* container) {
147 ConstrainedWebDialogDelegateViewViews* constrained_delegate = 175 ConstrainedWebDialogDelegateViewViews* constrained_delegate =
148 new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate) ; 176 new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate) ;
149 ConstrainedWindow* constrained_window = 177 ConstrainedWindow* constrained_window =
150 new ConstrainedWindowViews(container, constrained_delegate); 178 new ConstrainedWindowViews(container, constrained_delegate);
151 constrained_delegate->set_window(constrained_window); 179 constrained_delegate->set_window(constrained_window);
152 return constrained_delegate; 180 return constrained_delegate;
153 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698