| 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/views/html_dialog_view.h" | 5 #include "chrome/browser/ui/views/html_dialog_view.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 HtmlDialogView::~HtmlDialogView() { | 66 HtmlDialogView::~HtmlDialogView() { |
| 67 } | 67 } |
| 68 | 68 |
| 69 //////////////////////////////////////////////////////////////////////////////// | 69 //////////////////////////////////////////////////////////////////////////////// |
| 70 // HtmlDialogView, views::View implementation: | 70 // HtmlDialogView, views::View implementation: |
| 71 | 71 |
| 72 gfx::Size HtmlDialogView::GetPreferredSize() { | 72 gfx::Size HtmlDialogView::GetPreferredSize() { |
| 73 gfx::Size out; | 73 gfx::Size out; |
| 74 if (delegate_) | 74 if (delegate_) |
| 75 delegate_->GetDialogSize(&out); | 75 delegate_->GetMinimumDialogSize(&out); |
| 76 return out; | 76 return out; |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 79 bool HtmlDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 80 // Pressing ESC closes the dialog. | 80 // Pressing ESC closes the dialog. |
| 81 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 81 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); |
| 82 OnDialogClosed(std::string()); | 82 OnDialogClosed(std::string()); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 ui::ModalType HtmlDialogView::GetModalType() const { | 102 ui::ModalType HtmlDialogView::GetModalType() const { |
| 103 return GetDialogModalType(); | 103 return GetDialogModalType(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 string16 HtmlDialogView::GetWindowTitle() const { | 106 string16 HtmlDialogView::GetWindowTitle() const { |
| 107 if (delegate_) | 107 if (delegate_) |
| 108 return delegate_->GetDialogTitle(); | 108 return delegate_->GetDialogTitle(); |
| 109 return string16(); | 109 return string16(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 std::string HtmlDialogView::GetWindowName() const { |
| 113 if (delegate_) |
| 114 return delegate_->GetDialogName(); |
| 115 return std::string(); |
| 116 } |
| 117 |
| 112 void HtmlDialogView::WindowClosing() { | 118 void HtmlDialogView::WindowClosing() { |
| 113 // If we still have a delegate that means we haven't notified it of the | 119 // If we still have a delegate that means we haven't notified it of the |
| 114 // dialog closing. This happens if the user clicks the Close button on the | 120 // dialog closing. This happens if the user clicks the Close button on the |
| 115 // dialog. | 121 // dialog. |
| 116 if (delegate_) | 122 if (delegate_) |
| 117 OnDialogClosed(""); | 123 OnDialogClosed(""); |
| 118 } | 124 } |
| 119 | 125 |
| 120 views::View* HtmlDialogView::GetContentsView() { | 126 views::View* HtmlDialogView::GetContentsView() { |
| 121 return this; | 127 return this; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 std::vector<WebUIMessageHandler*>* handlers) const { | 166 std::vector<WebUIMessageHandler*>* handlers) const { |
| 161 if (delegate_) | 167 if (delegate_) |
| 162 delegate_->GetWebUIMessageHandlers(handlers); | 168 delegate_->GetWebUIMessageHandlers(handlers); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void HtmlDialogView::GetDialogSize(gfx::Size* size) const { | 171 void HtmlDialogView::GetDialogSize(gfx::Size* size) const { |
| 166 if (delegate_) | 172 if (delegate_) |
| 167 delegate_->GetDialogSize(size); | 173 delegate_->GetDialogSize(size); |
| 168 } | 174 } |
| 169 | 175 |
| 176 void HtmlDialogView::GetMinimumDialogSize(gfx::Size* size) const { |
| 177 if (delegate_) |
| 178 delegate_->GetMinimumDialogSize(size); |
| 179 } |
| 180 |
| 170 std::string HtmlDialogView::GetDialogArgs() const { | 181 std::string HtmlDialogView::GetDialogArgs() const { |
| 171 if (delegate_) | 182 if (delegate_) |
| 172 return delegate_->GetDialogArgs(); | 183 return delegate_->GetDialogArgs(); |
| 173 return std::string(); | 184 return std::string(); |
| 174 } | 185 } |
| 175 | 186 |
| 176 void HtmlDialogView::OnDialogClosed(const std::string& json_retval) { | 187 void HtmlDialogView::OnDialogClosed(const std::string& json_retval) { |
| 177 HtmlDialogTabContentsDelegate::Detach(); | 188 HtmlDialogTabContentsDelegate::Detach(); |
| 178 if (delegate_) { | 189 if (delegate_) { |
| 179 HtmlDialogUIDelegate* dialog_delegate = delegate_; | 190 // Store the dialog content area size. |
| 191 delegate_->StoreDialogSize(GetContentsBounds().size()); |
| 192 } |
| 193 |
| 194 if (GetWidget()) |
| 195 GetWidget()->Close(); |
| 196 |
| 197 if (delegate_) { |
| 198 delegate_->OnDialogClosed(json_retval); |
| 180 delegate_ = NULL; // We will not communicate further with the delegate. | 199 delegate_ = NULL; // We will not communicate further with the delegate. |
| 181 | |
| 182 // Store the dialog content area size. | |
| 183 dialog_delegate->StoreDialogSize(GetContentsBounds().size()); | |
| 184 | |
| 185 dialog_delegate->OnDialogClosed(json_retval); | |
| 186 } | 200 } |
| 187 GetWidget()->Close(); | |
| 188 } | 201 } |
| 189 | 202 |
| 190 void HtmlDialogView::OnCloseContents(WebContents* source, | 203 void HtmlDialogView::OnCloseContents(WebContents* source, |
| 191 bool* out_close_dialog) { | 204 bool* out_close_dialog) { |
| 192 if (delegate_) | 205 if (delegate_) |
| 193 delegate_->OnCloseContents(source, out_close_dialog); | 206 delegate_->OnCloseContents(source, out_close_dialog); |
| 194 } | 207 } |
| 195 | 208 |
| 196 bool HtmlDialogView::ShouldShowDialogTitle() const { | 209 bool HtmlDialogView::ShouldShowDialogTitle() const { |
| 197 if (delegate_) | 210 if (delegate_) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 290 |
| 278 WebContents* web_contents = dom_contents_->web_contents(); | 291 WebContents* web_contents = dom_contents_->web_contents(); |
| 279 web_contents->SetDelegate(this); | 292 web_contents->SetDelegate(this); |
| 280 | 293 |
| 281 // Set the delegate. This must be done before loading the page. See | 294 // Set the delegate. This must be done before loading the page. See |
| 282 // the comment above HtmlDialogUI in its header file for why. | 295 // the comment above HtmlDialogUI in its header file for why. |
| 283 HtmlDialogUI::GetPropertyAccessor().SetProperty( | 296 HtmlDialogUI::GetPropertyAccessor().SetProperty( |
| 284 web_contents->GetPropertyBag(), this); | 297 web_contents->GetPropertyBag(), this); |
| 285 tab_watcher_.reset(new TabRenderWatcher(web_contents, this)); | 298 tab_watcher_.reset(new TabRenderWatcher(web_contents, this)); |
| 286 | 299 |
| 300 if (delegate_) { |
| 301 gfx::Size out; |
| 302 delegate_->GetDialogSize(&out); |
| 303 if (!out.IsEmpty() && GetWidget()) |
| 304 GetWidget()->CenterWindow(out); |
| 305 } |
| 306 |
| 287 DOMView::LoadURL(GetDialogContentURL()); | 307 DOMView::LoadURL(GetDialogContentURL()); |
| 288 } | 308 } |
| 289 | 309 |
| 290 void HtmlDialogView::RegisterDialogAccelerators() { | 310 void HtmlDialogView::RegisterDialogAccelerators() { |
| 291 // Pressing the ESC key will close the dialog. | 311 // Pressing the ESC key will close the dialog. |
| 292 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false)); | 312 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false)); |
| 293 } | 313 } |
| 294 | 314 |
| 295 void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) { | 315 void HtmlDialogView::OnRenderHostCreated(content::RenderViewHost* host) { |
| 296 } | 316 } |
| 297 | 317 |
| 298 void HtmlDialogView::OnTabMainFrameLoaded() { | 318 void HtmlDialogView::OnTabMainFrameLoaded() { |
| 299 } | 319 } |
| 300 | 320 |
| 301 void HtmlDialogView::OnTabMainFrameRender() { | 321 void HtmlDialogView::OnTabMainFrameRender() { |
| 302 tab_watcher_.reset(); | 322 tab_watcher_.reset(); |
| 303 } | 323 } |
| OLD | NEW |