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

Side by Side Diff: chrome/browser/ui/gtk/validation_message_bubble_gtk.cc

Issue 16583005: Some improvement of validation message bubble UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/validation_message_bubble.h" 5 #include "chrome/browser/ui/validation_message_bubble.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" 9 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // A GTK implementation of ValidationMessageBubble. 28 // A GTK implementation of ValidationMessageBubble.
29 class ValidationMessageBubbleGtk : public chrome::ValidationMessageBubble, 29 class ValidationMessageBubbleGtk : public chrome::ValidationMessageBubble,
30 public BubbleDelegateGtk { 30 public BubbleDelegateGtk {
31 public: 31 public:
32 ValidationMessageBubbleGtk(content::RenderWidgetHost* widget_host, 32 ValidationMessageBubbleGtk(content::RenderWidgetHost* widget_host,
33 const gfx::Rect& anchor_in_screen, 33 const gfx::Rect& anchor_in_screen,
34 const string16& main_text, 34 const string16& main_text,
35 const string16& sub_text); 35 const string16& sub_text);
36 virtual ~ValidationMessageBubbleGtk(); 36 virtual ~ValidationMessageBubbleGtk();
37 virtual void SetPositionRelativeToAnchor(
38 content::RenderWidgetHost* widget_host,
39 const gfx::Rect& anchor_in_root_view) OVERRIDE;
37 40
38 // BubbleDelegateGtk override: 41 // BubbleDelegateGtk override:
39 virtual void BubbleClosing(BubbleGtk*, bool) OVERRIDE; 42 virtual void BubbleClosing(BubbleGtk*, bool) OVERRIDE;
40 43
41 private: 44 private:
42 static GtkWidget* ConstructContent(const string16& main_text, 45 static GtkWidget* ConstructContent(const string16& main_text,
43 const string16& sub_text); 46 const string16& sub_text);
44 47
45 BubbleGtk* bubble_; 48 BubbleGtk* bubble_;
46 }; 49 };
47 50
48 ValidationMessageBubbleGtk::ValidationMessageBubbleGtk( 51 ValidationMessageBubbleGtk::ValidationMessageBubbleGtk(
49 content::RenderWidgetHost* widget_host, 52 content::RenderWidgetHost* widget_host,
50 const gfx::Rect& anchor_in_screen, 53 const gfx::Rect& anchor_in_root_view,
51 const string16& main_text, 54 const string16& main_text,
52 const string16& sub_text) 55 const string16& sub_text)
53 : bubble_(NULL) { 56 : bubble_(NULL) {
54 if (!widget_host->IsRenderView()) 57 if (!widget_host->IsRenderView())
55 return; 58 return;
56 gfx::Rect bounds_in_screen = widget_host->GetView()->GetViewBounds();
57 gfx::Rect anchor = anchor_in_screen;
58 anchor.Offset(-bounds_in_screen.x(), -bounds_in_screen.y());
59
60 Profile* profile = Profile::FromBrowserContext( 59 Profile* profile = Profile::FromBrowserContext(
61 content::WebContents::FromRenderViewHost( 60 content::WebContents::FromRenderViewHost(
62 content::RenderViewHost::From(widget_host))->GetBrowserContext()); 61 content::RenderViewHost::From(widget_host))->GetBrowserContext());
63 bubble_ = BubbleGtk::Show(widget_host->GetView()->GetNativeView(), 62 bubble_ = BubbleGtk::Show(widget_host->GetView()->GetNativeView(),
64 &anchor, 63 &anchor_in_root_view,
65 ConstructContent(main_text, sub_text), 64 ConstructContent(main_text, sub_text),
66 BubbleGtk::ANCHOR_TOP_LEFT, 65 BubbleGtk::ANCHOR_TOP_LEFT,
67 BubbleGtk::POPUP_WINDOW, 66 BubbleGtk::POPUP_WINDOW,
68 GtkThemeService::GetFrom(profile), 67 GtkThemeService::GetFrom(profile),
69 this); 68 this);
70 } 69 }
71 70
72 ValidationMessageBubbleGtk::~ValidationMessageBubbleGtk() { 71 ValidationMessageBubbleGtk::~ValidationMessageBubbleGtk() {
73 if (bubble_) 72 if (bubble_)
74 bubble_->Close(); 73 bubble_->Close();
75 } 74 }
76 75
76 void ValidationMessageBubbleGtk::SetPositionRelativeToAnchor(
77 content::RenderWidgetHost* widget_host,
78 const gfx::Rect& anchor_in_root_view) {
79 if (bubble_)
80 bubble_->SetPositionRelativeToAnchor(&anchor_in_root_view);
81 }
82
77 void ValidationMessageBubbleGtk::BubbleClosing(BubbleGtk*, bool) { 83 void ValidationMessageBubbleGtk::BubbleClosing(BubbleGtk*, bool) {
78 bubble_ = NULL; 84 bubble_ = NULL;
79 } 85 }
80 86
81 // static 87 // static
82 GtkWidget* ValidationMessageBubbleGtk::ConstructContent( 88 GtkWidget* ValidationMessageBubbleGtk::ConstructContent(
83 const string16& main_text, const string16& sub_text) { 89 const string16& main_text, const string16& sub_text) {
84 GtkWidget* icon = gtk_image_new(); 90 GtkWidget* icon = gtk_image_new();
85 gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0); 91 gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0);
86 gtk_misc_set_padding(GTK_MISC(icon), kPadding, kPadding); 92 gtk_misc_set_padding(GTK_MISC(icon), kPadding, kPadding);
(...skipping 30 matching lines...) Expand all
117 gtk_container_add(GTK_CONTAINER(content), icon_text_box); 123 gtk_container_add(GTK_CONTAINER(content), icon_text_box);
118 return content; 124 return content;
119 } 125 }
120 126
121 } // namespace 127 } // namespace
122 128
123 namespace chrome { 129 namespace chrome {
124 130
125 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( 131 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
126 content::RenderWidgetHost* widget_host, 132 content::RenderWidgetHost* widget_host,
127 const gfx::Rect& anchor_in_screen, 133 const gfx::Rect& anchor_in_root_view,
128 const string16& main_text, 134 const string16& main_text,
129 const string16& sub_text) { 135 const string16& sub_text) {
130 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleGtk( 136 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleGtk(
131 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); 137 widget_host, anchor_in_root_view, main_text, sub_text)).Pass();
132 } 138 }
133 139
134 } // namespace chrome 140 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bubble/bubble_gtk.cc ('k') | chrome/browser/ui/validation_message_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698