Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: chrome/browser/ui/views/global_error_bubble_view.cc

Issue 7857014: patch for global error bubbles (view/gtk) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/global_error_bubble_view.h ('k') | chrome/browser/ui/views/toolbar_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/global_error_bubble_view.cc
diff --git a/chrome/browser/ui/views/global_error_bubble_view.cc b/chrome/browser/ui/views/global_error_bubble_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2288faeadaeccaad18833db2b57616b1860482ca
--- /dev/null
+++ b/chrome/browser/ui/views/global_error_bubble_view.cc
@@ -0,0 +1,149 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/global_error_bubble_view.h"
+
+#include "base/logging.h"
+#include "chrome/browser/ui/global_error_delegate.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/layout/layout_constants.h"
+
+namespace {
+
+enum {
+ TAG_ACCEPT_BUTTON = 1,
+ TAG_CANCEL_BUTTON,
+};
+
+const int kBubbleViewWidth = 262;
+
+} // namespace
+
+GlobalErrorBubbleView::GlobalErrorBubbleView(GlobalErrorDelegate* delegate,
+ Browser* browser)
+ : browser_(browser),
+ delegate_(delegate) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ int resource_id = delegate_->GetBubbleViewIconResourceID();
+ scoped_ptr<views::ImageView> image_view(new views::ImageView());
+ image_view->SetImage(rb.GetImageNamed(resource_id).ToSkBitmap());
+
+ string16 title_string(delegate_->GetBubbleViewTitle());
+ scoped_ptr<views::Label> title_label(
+ new views::Label(UTF16ToWideHack(title_string)));
+ title_label->SetMultiLine(true);
+ title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ title_label->SetFont(title_label->font().DeriveFont(1));
+
+ string16 message_string(delegate_->GetBubbleViewMessage());
+ scoped_ptr<views::Label> message_label(
+ new views::Label(UTF16ToWideHack(message_string)));
+ message_label->SetMultiLine(true);
+ message_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+
+ string16 accept_string(delegate_->GetBubbleViewAcceptButtonLabel());
+ scoped_ptr<views::TextButton> accept_button(
+ new views::NativeTextButton(this, UTF16ToWideHack(accept_string)));
+ accept_button->SetIsDefault(true);
+
+ string16 cancel_string(delegate->GetBubbleViewCancelButtonLabel());
+ scoped_ptr<views::TextButton> cancel_button;
+ if (!cancel_string.empty()) {
+ cancel_button.reset(
+ new views::NativeTextButton(this, UTF16ToWideHack(cancel_string)));
+ }
+
+ views::GridLayout* layout = new views::GridLayout(this);
+ SetLayoutManager(layout);
+
+ // Top row, icon and title.
+ views::ColumnSet* cs = layout->AddColumnSet(0);
+ cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+
+ // Middle row, message label.
+ cs = layout->AddColumnSet(1);
+ cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+
+ // Bottom row, accept and cancel button.
+ cs = layout->AddColumnSet(2);
+ cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
+ cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
+ cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(1, 0);
+ layout->AddView(image_view.release());
+ layout->AddView(title_label.release());
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
+
+ layout->StartRow(1, 1);
+ layout->AddView(message_label.release());
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
+
+ layout->StartRow(0, 2);
+ if (cancel_button.get())
+ layout->AddView(cancel_button.release());
+ else
+ layout->SkipColumns(1);
+ layout->AddView(accept_button.release());
+}
+
+GlobalErrorBubbleView::~GlobalErrorBubbleView() {
+}
+
+gfx::Size GlobalErrorBubbleView::GetPreferredSize() {
+ views::GridLayout* layout =
+ static_cast<views::GridLayout*>(GetLayoutManager());
+ int height = layout->GetPreferredHeightForWidth(this, kBubbleViewWidth);
+ return gfx::Size(kBubbleViewWidth, height);
+}
+
+void GlobalErrorBubbleView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender->tag() == TAG_ACCEPT_BUTTON)
+ delegate_->BubbleViewAcceptButtonPressed();
+ else if (sender->tag() == TAG_CANCEL_BUTTON)
+ delegate_->BubbleViewCancelButtonPressed();
+ else
+ NOTREACHED();
+}
+
+void GlobalErrorBubbleView::BubbleClosing(Bubble* bubble,
+ bool closed_by_escape) {
+}
+
+bool GlobalErrorBubbleView::CloseOnEscape() {
+ return true;
+}
+
+bool GlobalErrorBubbleView::FadeInOnShow() {
+ return true;
+}
+
+void GlobalErrorDelegate::ShowBubbleView(
+ GlobalErrorDelegate* delegate,
+ Browser* browser,
+ const gfx::Rect& position_relative_to) {
+ BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(
+ browser->window()->GetNativeHandle());
+
+ gfx::Rect bounds(300, 300, 40, 40);
+ GlobalErrorBubbleView* bubble_view =
+ new GlobalErrorBubbleView(delegate, browser);
+ // Bubble::Show() takes ownership of the view.
+ Bubble::Show(browser_view->GetWidget(), bounds,
+ views::BubbleBorder::TOP_RIGHT, bubble_view, bubble_view);
+}
« no previous file with comments | « chrome/browser/ui/views/global_error_bubble_view.h ('k') | chrome/browser/ui/views/toolbar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698