Chromium Code Reviews| 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/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" | |
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
| 130 AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | |
|
kochi
2012/05/30 07:17:31
style nit: newline after open paren.
virtual bool
yoshiki
2012/05/30 08:43:15
Done.
| |
| 131 // Pressing ESC closes the dialog. | |
| 132 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | |
| 133 if (GetWidget()) | |
| 134 GetWidget()->Close(); | |
| 135 return true; | |
| 136 }; | |
|
kochi
2012/05/30 07:17:31
nit: a newline after this line.
yoshiki
2012/05/30 08:43:15
Other inherited methods are listed without blank l
| |
| 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 the ESC key will close the dialog. | |
|
kochi
2012/05/30 07:17:31
probably "the" is not necessary.
You can reuse the
yoshiki
2012/05/30 08:43:15
Done.
| |
| 161 set_allow_accelerators(true); | |
| 162 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | |
|
kochi
2012/05/30 07:17:31
Don't we need to RemoveAccelerator()?
(I'm not sur
yoshiki
2012/05/30 08:43:15
I think it is not necessarily because WebDialogVie
| |
| 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 } |
| OLD | NEW |