diff options
author | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 16:29:33 +0000 |
---|---|---|
committer | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 16:29:33 +0000 |
commit | dcc4b3d55f52e20607db856a1c1bc409e9531eac (patch) | |
tree | 1ce6b74dd5f7ea77c0eee047d67877d75c2634ee | |
parent | 5768a291152cae3310c4e680ca7f6d88889b000d (diff) | |
download | chromium_src-dcc4b3d55f52e20607db856a1c1bc409e9531eac.zip chromium_src-dcc4b3d55f52e20607db856a1c1bc409e9531eac.tar.gz chromium_src-dcc4b3d55f52e20607db856a1c1bc409e9531eac.tar.bz2 |
Merge 64436 - Add optional close button for BubbleWindow.
Use this for proxy settings dialog at OOBE.
BUG=http://crosbug.com/8235
TEST=Manual
Review URL: http://codereview.chromium.org/4124005
TBR=dilmah@chromium.org
Review URL: http://codereview.chromium.org/4124010
git-svn-id: svn://svn.chromium.org/chrome/branches/552/src@64439 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_frame_view.cc | 60 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_frame_view.h | 18 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_window.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/bubble_window.h | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_html_dialog.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_html_dialog.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/window.cc | 5 |
7 files changed, 96 insertions, 16 deletions
diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.cc b/chrome/browser/chromeos/frame/bubble_frame_view.cc index 5f0207c..e8caded 100644 --- a/chrome/browser/chromeos/frame/bubble_frame_view.cc +++ b/chrome/browser/chromeos/frame/bubble_frame_view.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/frame/bubble_frame_view.h" +#include "app/resource_bundle.h" #include "gfx/canvas_skia.h" #include "gfx/font.h" #include "gfx/insets.h" @@ -11,6 +12,8 @@ #include "gfx/rect.h" #include "chrome/browser/chromeos/frame/bubble_window.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/window/hit_test.h" #include "views/window/window.h" @@ -27,15 +30,30 @@ static const int kHorizontalPadding = 10; namespace chromeos { -BubbleFrameView::BubbleFrameView(views::Window* frame) +BubbleFrameView::BubbleFrameView(views::Window* frame, + BubbleWindow::Style style) : frame_(frame), - title_(NULL) { + style_(style), + title_(NULL), + close_button_(NULL) { set_border(new BubbleBorder(BubbleBorder::NONE)); title_ = new views::Label(frame_->GetDelegate()->GetWindowTitle()); title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); title_->SetFont(title_->font().DeriveFont(1, gfx::Font::BOLD)); AddChildView(title_); + + if (style_ & BubbleWindow::STYLE_XBAR) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + close_button_ = new views::ImageButton(this); + close_button_->SetImage(views::CustomButton::BS_NORMAL, + rb.GetBitmapNamed(IDR_CLOSE_BAR)); + close_button_->SetImage(views::CustomButton::BS_HOT, + rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); + close_button_->SetImage(views::CustomButton::BS_PUSHED, + rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); + AddChildView(close_button_); + } } BubbleFrameView::~BubbleFrameView() { @@ -49,7 +67,15 @@ gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const { gfx::Insets insets = GetInsets(); gfx::Size title_size = title_->GetPreferredSize(); - int top_height = insets.top() + title_size.height() + kTitleContentPadding; + + gfx::Size close_button_size = gfx::Size(); + if (close_button_) { + close_button_size = close_button_->GetPreferredSize(); + } + + int top_height = insets.top() + + std::max(title_size.height(), close_button_size.height()) + + kTitleContentPadding; return gfx::Rect(std::max(0, client_bounds.x() - insets.left()), std::max(0, client_bounds.y() - top_height), client_bounds.width() + insets.width(), @@ -93,11 +119,26 @@ void BubbleFrameView::Layout() { gfx::Insets insets = GetInsets(); gfx::Size title_size = title_->GetPreferredSize(); - title_->SetBounds(insets.left(), insets.top(), - std::max(0, width() - insets.width()), + + gfx::Size close_button_size = gfx::Size(); + if (close_button_) { + close_button_size = close_button_->GetPreferredSize(); + } + + title_->SetBounds( + insets.left(), insets.top(), + std::max(0, width() - insets.width() - close_button_size.width()), title_size.height()); - int top_height = insets.top() + title_size.height() + kTitleContentPadding; + if (close_button_) { + close_button_->SetBounds( + width() - insets.right() - close_button_size.width(), insets.top(), + close_button_size.width(), close_button_size.height()); + } + + int top_height = insets.top() + + std::max(title_size.height(), close_button_size.height()) + + kTitleContentPadding; client_view_bounds_.SetRect(insets.left(), top_height, std::max(0, width() - insets.width()), std::max(0, height() - top_height - insets.bottom())); @@ -122,4 +163,11 @@ void BubbleFrameView::Paint(gfx::Canvas* canvas) { PaintBorder(canvas); } +void BubbleFrameView::ButtonPressed(views::Button* sender, + const views::Event& event) { + 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 18505f7..7ebb29e 100644 --- a/chrome/browser/chromeos/frame/bubble_frame_view.h +++ b/chrome/browser/chromeos/frame/bubble_frame_view.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_CHROMEOS_FRAME_BUBBLE_FRAME_VIEW_H_ #pragma once +#include "chrome/browser/chromeos/frame/bubble_window.h" +#include "views/controls/button/button.h" #include "views/window/non_client_view.h" namespace gfx { @@ -17,6 +19,7 @@ class Size; } namespace views { +class ImageButton; class Label; class Window; } @@ -24,9 +27,10 @@ class Window; namespace chromeos { // BubbleFrameView implements a BubbleBorder based window frame. -class BubbleFrameView : public views::NonClientFrameView { +class BubbleFrameView : public views::NonClientFrameView, + public views::ButtonListener { public: - explicit BubbleFrameView(views::Window* frame); + BubbleFrameView(views::Window* frame, BubbleWindow::Style style); virtual ~BubbleFrameView(); // Overridden from views::NonClientFrameView: @@ -44,16 +48,26 @@ class BubbleFrameView : public views::NonClientFrameView { virtual void Layout(); virtual void Paint(gfx::Canvas* canvas); + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, + const views::Event& event); + private: // The window that owns this view. views::Window* frame_; + // Allows to tweak appearance of the view. + BubbleWindow::Style style_; + // Title label views::Label* title_; // The bounds of the client view, in this view's coordinates. gfx::Rect client_view_bounds_; + // Close button for STYLE_XBAR case. + views::ImageButton* close_button_; + DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); }; diff --git a/chrome/browser/chromeos/frame/bubble_window.cc b/chrome/browser/chromeos/frame/bubble_window.cc index 79a0c57..e5438d5 100644 --- a/chrome/browser/chromeos/frame/bubble_window.cc +++ b/chrome/browser/chromeos/frame/bubble_window.cc @@ -32,9 +32,10 @@ void BubbleWindow::Init(GtkWindow* parent, const gfx::Rect& bounds) { views::Window* BubbleWindow::Create( gfx::NativeWindow parent, const gfx::Rect& bounds, + Style style, views::WindowDelegate* window_delegate) { BubbleWindow* window = new BubbleWindow(window_delegate); - window->GetNonClientView()->SetFrameView(new BubbleFrameView(window)); + window->GetNonClientView()->SetFrameView(new BubbleFrameView(window, style)); window->Init(parent, bounds); chromeos::WmIpc::instance()->SetWindowType( diff --git a/chrome/browser/chromeos/frame/bubble_window.h b/chrome/browser/chromeos/frame/bubble_window.h index a6afbd7..fca4805 100644 --- a/chrome/browser/chromeos/frame/bubble_window.h +++ b/chrome/browser/chromeos/frame/bubble_window.h @@ -22,8 +22,14 @@ namespace chromeos { // A window that uses BubbleFrameView as its frame. 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). + }; + static views::Window* Create(gfx::NativeWindow parent, const gfx::Rect& bounds, + Style style, views::WindowDelegate* window_delegate); static const SkColor kBackgroundColor; @@ -33,6 +39,8 @@ 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 47e3e4b..f97065c 100644 --- a/chrome/browser/chromeos/login/login_html_dialog.cc +++ b/chrome/browser/chromeos/login/login_html_dialog.cc @@ -45,11 +45,11 @@ LoginHtmlDialog::LoginHtmlDialog(Delegate* delegate, const std::wstring& title, const GURL& url, Style style) - : style_(style), - delegate_(delegate), + : delegate_(delegate), parent_window_(parent_window), title_(title), - url_(url) { + url_(url), + style_(style) { gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width()); height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height()); @@ -65,11 +65,16 @@ void LoginHtmlDialog::Show() { this); switch (style_) { case STYLE_BUBBLE: - chromeos::BubbleWindow::Create(parent_window_, gfx::Rect(), html_view); + 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); + views::Window::CreateChromeWindow(parent_window_, + gfx::Rect(), + html_view); break; } html_view->InitDialog(); diff --git a/chrome/browser/chromeos/login/login_html_dialog.h b/chrome/browser/chromeos/login/login_html_dialog.h index 65c3116..9bb4ee6 100644 --- a/chrome/browser/chromeos/login/login_html_dialog.h +++ b/chrome/browser/chromeos/login/login_html_dialog.h @@ -29,7 +29,7 @@ class LoginHtmlDialog : public HtmlDialogUIDelegate { enum Style { STYLE_GENERIC, // Use generic CreateChromeWindow as a host. STYLE_BUBBLE // Use chromeos::BubbleWindow as a host. - } style_; + }; LoginHtmlDialog(Delegate* delegate, gfx::NativeWindow parent_window, @@ -65,6 +65,7 @@ class LoginHtmlDialog : public HtmlDialogUIDelegate { gfx::NativeWindow parent_window_; std::wstring title_; GURL url_; + Style style_; // Dialog display size. int width_; diff --git a/chrome/browser/views/window.cc b/chrome/browser/views/window.cc index bd8a304..ae28ce4 100644 --- a/chrome/browser/views/window.cc +++ b/chrome/browser/views/window.cc @@ -17,7 +17,10 @@ views::Window* CreateViewsWindow(gfx::NativeWindow parent, const gfx::Rect& bounds, views::WindowDelegate* delegate) { #if defined(OS_CHROMEOS) - return chromeos::BubbleWindow::Create(parent, gfx::Rect(), delegate); + return chromeos::BubbleWindow::Create(parent, + gfx::Rect(), + chromeos::BubbleWindow::STYLE_GENERIC, + delegate); #else return views::Window::CreateChromeWindow(parent, gfx::Rect(), delegate); #endif |