| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/login/login_html_dialog.h" | 5 #include "chrome/browser/chromeos/login/login_html_dialog.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/frame/bubble_frame_view.h" | 7 #include "chrome/browser/chromeos/frame/bubble_frame_view.h" |
| 8 #include "chrome/browser/chromeos/frame/bubble_window.h" | 8 #include "chrome/browser/chromeos/frame/bubble_window.h" |
| 9 #include "chrome/browser/chromeos/login/helper.h" | 9 #include "chrome/browser/chromeos/login/helper.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/ui/views/html_dialog_view.h" | 11 #include "chrome/browser/ui/views/html_dialog_view.h" |
| 12 #include "content/common/notification_service.h" | 12 #include "content/common/notification_service.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 16 #include "views/window/window.h" | 16 #include "views/window/window.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 // Default width/height ratio of screen size. | 21 // Default width/height ratio of screen size. |
| 22 const double kDefaultWidthRatio = 0.6; | 22 const double kDefaultWidthRatio = 0.6; |
| 23 const double kDefaultHeightRatio = 0.6; | 23 const double kDefaultHeightRatio = 0.6; |
| 24 | 24 |
| 25 // Custom HtmlDialogView with disabled context menu. | |
| 26 class HtmlDialogWithoutContextMenuView : public HtmlDialogView { | |
| 27 public: | |
| 28 HtmlDialogWithoutContextMenuView(Profile* profile, | |
| 29 HtmlDialogUIDelegate* delegate) | |
| 30 : HtmlDialogView(profile, delegate) {} | |
| 31 virtual ~HtmlDialogWithoutContextMenuView() {} | |
| 32 | |
| 33 // TabContentsDelegate implementation. | |
| 34 bool HandleContextMenu(const ContextMenuParams& params) { | |
| 35 // Disable context menu. | |
| 36 return true; | |
| 37 } | |
| 38 }; | |
| 39 | |
| 40 } // namespace | 25 } // namespace |
| 41 | 26 |
| 42 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 43 // LoginHtmlDialog, public: | 28 // LoginHtmlDialog, public: |
| 44 | 29 |
| 45 LoginHtmlDialog::LoginHtmlDialog(Delegate* delegate, | 30 LoginHtmlDialog::LoginHtmlDialog(Delegate* delegate, |
| 46 gfx::NativeWindow parent_window, | 31 gfx::NativeWindow parent_window, |
| 47 const std::wstring& title, | 32 const std::wstring& title, |
| 48 const GURL& url, | 33 const GURL& url, |
| 49 Style style) | 34 Style style) |
| 50 : delegate_(delegate), | 35 : delegate_(delegate), |
| 51 parent_window_(parent_window), | 36 parent_window_(parent_window), |
| 52 title_(title), | 37 title_(title), |
| 53 url_(url), | 38 url_(url), |
| 54 style_(style), | 39 style_(style), |
| 55 bubble_frame_view_(NULL), | 40 bubble_frame_view_(NULL), |
| 56 is_open_(false) { | 41 is_open_(false) { |
| 57 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); | 42 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); |
| 58 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); | 43 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); |
| 59 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); | 44 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); |
| 60 } | 45 } |
| 61 | 46 |
| 62 LoginHtmlDialog::~LoginHtmlDialog() { | 47 LoginHtmlDialog::~LoginHtmlDialog() { |
| 63 delegate_ = NULL; | 48 delegate_ = NULL; |
| 64 } | 49 } |
| 65 | 50 |
| 66 void LoginHtmlDialog::Show() { | 51 void LoginHtmlDialog::Show() { |
| 67 HtmlDialogWithoutContextMenuView* html_view = | 52 HtmlDialogView* html_view = |
| 68 new HtmlDialogWithoutContextMenuView(ProfileManager::GetDefaultProfile(), | 53 new HtmlDialogView(ProfileManager::GetDefaultProfile(), this); |
| 69 this); | |
| 70 if (style_ & STYLE_BUBBLE) { | 54 if (style_ & STYLE_BUBBLE) { |
| 71 views::Window* bubble_window = BubbleWindow::Create( | 55 views::Window* bubble_window = BubbleWindow::Create( |
| 72 parent_window_, gfx::Rect(), | 56 parent_window_, gfx::Rect(), |
| 73 static_cast<BubbleWindow::Style>( | 57 static_cast<BubbleWindow::Style>( |
| 74 BubbleWindow::STYLE_XBAR | BubbleWindow::STYLE_THROBBER), | 58 BubbleWindow::STYLE_XBAR | BubbleWindow::STYLE_THROBBER), |
| 75 html_view); | 59 html_view); |
| 76 bubble_frame_view_ = static_cast<BubbleFrameView*>( | 60 bubble_frame_view_ = static_cast<BubbleFrameView*>( |
| 77 bubble_window->non_client_view()->frame_view()); | 61 bubble_window->non_client_view()->frame_view()); |
| 78 } else { | 62 } else { |
| 79 views::Window::CreateChromeWindow(parent_window_, gfx::Rect(), html_view); | 63 views::Window::CreateChromeWindow(parent_window_, gfx::Rect(), html_view); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 void LoginHtmlDialog::OnCloseContents(TabContents* source, | 116 void LoginHtmlDialog::OnCloseContents(TabContents* source, |
| 133 bool* out_close_dialog) { | 117 bool* out_close_dialog) { |
| 134 if (out_close_dialog) | 118 if (out_close_dialog) |
| 135 *out_close_dialog = true; | 119 *out_close_dialog = true; |
| 136 } | 120 } |
| 137 | 121 |
| 138 bool LoginHtmlDialog::ShouldShowDialogTitle() const { | 122 bool LoginHtmlDialog::ShouldShowDialogTitle() const { |
| 139 return true; | 123 return true; |
| 140 } | 124 } |
| 141 | 125 |
| 126 bool LoginHtmlDialog::HandleContextMenu(const ContextMenuParams& params) { |
| 127 // Disable context menu. |
| 128 return true; |
| 129 } |
| 130 |
| 142 void LoginHtmlDialog::Observe(NotificationType type, | 131 void LoginHtmlDialog::Observe(NotificationType type, |
| 143 const NotificationSource& source, | 132 const NotificationSource& source, |
| 144 const NotificationDetails& details) { | 133 const NotificationDetails& details) { |
| 145 DCHECK(type.value == NotificationType::LOAD_COMPLETED_MAIN_FRAME); | 134 DCHECK(type.value == NotificationType::LOAD_COMPLETED_MAIN_FRAME); |
| 146 if (bubble_frame_view_) | 135 if (bubble_frame_view_) |
| 147 bubble_frame_view_->StopThrobber(); | 136 bubble_frame_view_->StopThrobber(); |
| 148 } | 137 } |
| 149 | 138 |
| 150 } // namespace chromeos | 139 } // namespace chromeos |
| OLD | NEW |