diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_frame_view.cc | 79 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_frame_view.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_window.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_html_dialog.cc | 43 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_html_dialog.h | 14 |
5 files changed, 109 insertions, 39 deletions
diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.cc b/chrome/browser/chromeos/frame/bubble_frame_view.cc index becfb78..9fe97c2 100644 --- a/chrome/browser/chromeos/frame/bubble_frame_view.cc +++ b/chrome/browser/chromeos/frame/bubble_frame_view.cc @@ -11,10 +11,12 @@ #include "gfx/path.h" #include "gfx/rect.h" #include "chrome/browser/chromeos/frame/bubble_window.h" +#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/views/bubble_border.h" #include "grit/theme_resources.h" #include "views/controls/button/image_button.h" #include "views/controls/label.h" +#include "views/controls/throbber.h" #include "views/window/hit_test.h" #include "views/window/window.h" #include "views/window/window_delegate.h" @@ -35,7 +37,8 @@ BubbleFrameView::BubbleFrameView(views::Window* frame, : frame_(frame), style_(style), title_(NULL), - close_button_(NULL) { + close_button_(NULL), + throbber_(NULL) { set_border(new BubbleBorder(BubbleBorder::NONE)); if (frame_->GetDelegate()->ShouldShowWindowTitle()) { @@ -56,11 +59,30 @@ BubbleFrameView::BubbleFrameView(views::Window* frame, rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); AddChildView(close_button_); } + + if (style_ & BubbleWindow::STYLE_THROBBER) { + throbber_ = CreateDefaultSmoothedThrobber(); + AddChildView(throbber_); + } } BubbleFrameView::~BubbleFrameView() { } +void BubbleFrameView::StartThrobber() { + DCHECK(throbber_ != NULL); + if (title_) + title_->SetText(std::wstring()); + throbber_->Start(); +} + +void BubbleFrameView::StopThrobber() { + DCHECK(throbber_ != NULL); + throbber_->Stop(); + if (title_) + title_->SetText(frame_->GetDelegate()->GetWindowTitle()); +} + gfx::Rect BubbleFrameView::GetBoundsForClientView() const { return client_view_bounds_; } @@ -68,20 +90,25 @@ gfx::Rect BubbleFrameView::GetBoundsForClientView() const { gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const { gfx::Insets insets = GetInsets(); + gfx::Size title_size; - if (title_) { + if (title_) title_size = title_->GetPreferredSize(); - } - - gfx::Size close_button_size = gfx::Size(); - if (close_button_) { + gfx::Size close_button_size; + if (close_button_) close_button_size = close_button_->GetPreferredSize(); - } + gfx::Size throbber_size; + if (throbber_) + throbber_size = throbber_->GetPreferredSize(); int top_height = insets.top(); - if (title_size.height() > 0 || close_button_size.height() > 0) - top_height += std::max(title_size.height(), close_button_size.height()) + - kTitleContentPadding; + if (title_size.height() > 0 || + close_button_size.height() > 0 || + throbber_size.height() > 0) { + top_height += kTitleContentPadding + std::max( + std::max(title_size.height(), close_button_size.height()), + throbber_size.height()); + } return gfx::Rect(std::max(0, client_bounds.x() - insets.left()), std::max(0, client_bounds.y() - top_height), client_bounds.width() + insets.width(), @@ -125,14 +152,14 @@ void BubbleFrameView::Layout() { gfx::Insets insets = GetInsets(); gfx::Size title_size; - if (title_) { + if (title_) title_size = title_->GetPreferredSize(); - } - - gfx::Size close_button_size = gfx::Size(); - if (close_button_) { + gfx::Size close_button_size; + if (close_button_) close_button_size = close_button_->GetPreferredSize(); - } + gfx::Size throbber_size; + if (throbber_) + throbber_size = throbber_->GetPreferredSize(); if (title_) { title_->SetBounds( @@ -147,10 +174,21 @@ void BubbleFrameView::Layout() { close_button_size.width(), close_button_size.height()); } + if (throbber_) { + throbber_->SetBounds( + insets.left(), insets.top(), + std::min(throbber_size.width(), width()), + throbber_size.height()); + } + int top_height = insets.top(); - if (title_size.height() > 0 || close_button_size.height() > 0) - top_height += std::max(title_size.height(), close_button_size.height()) + - kTitleContentPadding; + if (title_size.height() > 0 || + close_button_size.height() > 0 || + throbber_size.height() > 0) { + top_height += kTitleContentPadding + std::max( + std::max(title_size.height(), close_button_size.height()), + throbber_size.height()); + } client_view_bounds_.SetRect(insets.left(), top_height, std::max(0, width() - insets.width()), std::max(0, height() - top_height - insets.bottom())); @@ -177,9 +215,8 @@ void BubbleFrameView::Paint(gfx::Canvas* canvas) { void BubbleFrameView::ButtonPressed(views::Button* sender, const views::Event& event) { - if (close_button_ != NULL && sender == close_button_) { + if (close_button_ != NULL && sender == close_button_) frame_->Close(); - } } } // namespace chromeos diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.h b/chrome/browser/chromeos/frame/bubble_frame_view.h index 7ebb29e..dd32530 100644 --- a/chrome/browser/chromeos/frame/bubble_frame_view.h +++ b/chrome/browser/chromeos/frame/bubble_frame_view.h @@ -52,6 +52,9 @@ class BubbleFrameView : public views::NonClientFrameView, virtual void ButtonPressed(views::Button* sender, const views::Event& event); + void StartThrobber(); + void StopThrobber(); + private: // The window that owns this view. views::Window* frame_; @@ -68,6 +71,9 @@ class BubbleFrameView : public views::NonClientFrameView, // Close button for STYLE_XBAR case. views::ImageButton* close_button_; + // Throbber is optional. Employed by STYLE_THROBBER. + views::Throbber* throbber_; + DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); }; diff --git a/chrome/browser/chromeos/frame/bubble_window.h b/chrome/browser/chromeos/frame/bubble_window.h index fca4805..a3b313e 100644 --- a/chrome/browser/chromeos/frame/bubble_window.h +++ b/chrome/browser/chromeos/frame/bubble_window.h @@ -14,6 +14,7 @@ class Rect; } namespace views { +class Throbber; class WindowDelegate; } @@ -24,7 +25,8 @@ class BubbleWindow : public views::WindowGtk { public: enum Style { STYLE_GENERIC = 0, // Default style. - STYLE_XBAR = 1 << 0 // Show close button at the top right (left for RTL). + STYLE_XBAR = 1 << 0, // Show close button at the top right (left for RTL). + STYLE_THROBBER = 1 << 1 // Show throbber for slow rendering. }; static views::Window* Create(gfx::NativeWindow parent, @@ -39,8 +41,6 @@ class BubbleWindow : public views::WindowGtk { // Overidden from views::WindowGtk: virtual void Init(GtkWindow* parent, const gfx::Rect& bounds); - - Style style_; }; } // namespace chromeos diff --git a/chrome/browser/chromeos/login/login_html_dialog.cc b/chrome/browser/chromeos/login/login_html_dialog.cc index e8ae340..f0ff81a 100644 --- a/chrome/browser/chromeos/login/login_html_dialog.cc +++ b/chrome/browser/chromeos/login/login_html_dialog.cc @@ -4,10 +4,12 @@ #include "chrome/browser/chromeos/login/login_html_dialog.h" +#include "chrome/browser/chromeos/frame/bubble_frame_view.h" #include "chrome/browser/chromeos/frame/bubble_window.h" #include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/views/html_dialog_view.h" +#include "chrome/common/notification_service.h" #include "gfx/native_widget_types.h" #include "gfx/rect.h" #include "gfx/size.h" @@ -49,7 +51,8 @@ LoginHtmlDialog::LoginHtmlDialog(Delegate* delegate, parent_window_(parent_window), title_(title), url_(url), - style_(style) { + style_(style), + bubble_frame_view_(NULL) { gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); @@ -63,19 +66,23 @@ void LoginHtmlDialog::Show() { HtmlDialogWithoutContextMenuView* html_view = new HtmlDialogWithoutContextMenuView(ProfileManager::GetDefaultProfile(), this); - switch (style_) { - case STYLE_BUBBLE: - chromeos::BubbleWindow::Create(parent_window_, - gfx::Rect(), - chromeos::BubbleWindow::STYLE_XBAR, - html_view); - break; - case STYLE_GENERIC: - default: - views::Window::CreateChromeWindow(parent_window_, - gfx::Rect(), - html_view); - break; + if (style_ & STYLE_BUBBLE) { + views::Window* bubble_window = BubbleWindow::Create( + parent_window_, gfx::Rect(), + static_cast<BubbleWindow::Style>( + BubbleWindow::STYLE_XBAR | BubbleWindow::STYLE_THROBBER), + html_view); + bubble_frame_view_ = static_cast<BubbleFrameView*>( + bubble_window->GetNonClientView()->frame_view()); + } else { + (void)views::Window::CreateChromeWindow( + parent_window_, gfx::Rect(), html_view); + } + if (bubble_frame_view_) { + bubble_frame_view_->StartThrobber(); + notification_registrar_.Add(this, + NotificationType::LOAD_COMPLETED_MAIN_FRAME, + NotificationService::AllSources()); } html_view->InitDialog(); html_view->window()->Show(); @@ -87,6 +94,14 @@ void LoginHtmlDialog::SetDialogSize(int width, int height) { height_ = height; } +void LoginHtmlDialog::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type.value == NotificationType::LOAD_COMPLETED_MAIN_FRAME); + if (bubble_frame_view_) + bubble_frame_view_->StopThrobber(); +} + /////////////////////////////////////////////////////////////////////////////// // LoginHtmlDialog, protected: diff --git a/chrome/browser/chromeos/login/login_html_dialog.h b/chrome/browser/chromeos/login/login_html_dialog.h index 45f4d88..0955395 100644 --- a/chrome/browser/chromeos/login/login_html_dialog.h +++ b/chrome/browser/chromeos/login/login_html_dialog.h @@ -9,13 +9,18 @@ #include <string> #include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "gfx/native_widget_types.h" #include "gfx/size.h" namespace chromeos { +class BubbleFrameView; + // Launches html dialog during OOBE/Login with specified URL and title. -class LoginHtmlDialog : public HtmlDialogUIDelegate { +class LoginHtmlDialog : public HtmlDialogUIDelegate, + public NotificationObserver { public: // Delegate class to get notifications from the dialog. class Delegate { @@ -59,6 +64,11 @@ class LoginHtmlDialog : public HtmlDialogUIDelegate { virtual void OnCloseContents(TabContents* source, bool* out_close_dialog); virtual bool ShouldShowDialogTitle() const { return true; } + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + private: // Notifications receiver. Delegate* delegate_; @@ -67,6 +77,8 @@ class LoginHtmlDialog : public HtmlDialogUIDelegate { std::wstring title_; GURL url_; Style style_; + NotificationRegistrar notification_registrar_; + BubbleFrameView* bubble_frame_view_; // Dialog display size. int width_; |