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

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: 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/utf_string_conversions.h" 7 #include "base/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 MoveOnAnchor(content::RenderWidgetHost* widget_host,
38 const gfx::Rect& anchor_in_root_view) OVERRIDE;
37 39
38 // BubbleDelegateGtk override: 40 // BubbleDelegateGtk override:
39 virtual void BubbleClosing(BubbleGtk*, bool) OVERRIDE; 41 virtual void BubbleClosing(BubbleGtk*, bool) OVERRIDE;
40 42
41 private: 43 private:
42 static GtkWidget* ConstructContent(const string16& main_text, 44 static GtkWidget* ConstructContent(const string16& main_text,
43 const string16& sub_text); 45 const string16& sub_text);
44 46
45 BubbleGtk* bubble_; 47 BubbleGtk* bubble_;
46 }; 48 };
47 49
48 ValidationMessageBubbleGtk::ValidationMessageBubbleGtk( 50 ValidationMessageBubbleGtk::ValidationMessageBubbleGtk(
49 content::RenderWidgetHost* widget_host, 51 content::RenderWidgetHost* widget_host,
50 const gfx::Rect& anchor_in_screen, 52 const gfx::Rect& anchor_in_root_view,
51 const string16& main_text, 53 const string16& main_text,
52 const string16& sub_text) 54 const string16& sub_text)
53 : bubble_(NULL) { 55 : bubble_(NULL) {
54 if (!widget_host->IsRenderView()) 56 if (!widget_host->IsRenderView())
55 return; 57 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( 58 Profile* profile = Profile::FromBrowserContext(
61 content::WebContents::FromRenderViewHost( 59 content::WebContents::FromRenderViewHost(
62 content::RenderViewHost::From(widget_host))->GetBrowserContext()); 60 content::RenderViewHost::From(widget_host))->GetBrowserContext());
63 bubble_ = BubbleGtk::Show(widget_host->GetView()->GetNativeView(), 61 bubble_ = BubbleGtk::Show(widget_host->GetView()->GetNativeView(),
64 &anchor, 62 &anchor_in_root_view,
65 ConstructContent(main_text, sub_text), 63 ConstructContent(main_text, sub_text),
66 BubbleGtk::ANCHOR_TOP_LEFT, 64 BubbleGtk::ANCHOR_TOP_LEFT,
67 BubbleGtk::POPUP_WINDOW, 65 BubbleGtk::POPUP_WINDOW,
68 GtkThemeService::GetFrom(profile), 66 GtkThemeService::GetFrom(profile),
69 this); 67 this);
70 } 68 }
71 69
72 ValidationMessageBubbleGtk::~ValidationMessageBubbleGtk() { 70 ValidationMessageBubbleGtk::~ValidationMessageBubbleGtk() {
73 if (bubble_) 71 if (bubble_)
74 bubble_->Close(); 72 bubble_->Close();
75 } 73 }
76 74
75 void ValidationMessageBubbleGtk::MoveOnAnchor(
76 content::RenderWidgetHost* widget_host,
77 const gfx::Rect& anchor_in_root_view) {
78 if (bubble_)
79 bubble_->UpdateAnchorRect(&anchor_in_root_view);
80 }
81
77 void ValidationMessageBubbleGtk::BubbleClosing(BubbleGtk*, bool) { 82 void ValidationMessageBubbleGtk::BubbleClosing(BubbleGtk*, bool) {
78 bubble_ = NULL; 83 bubble_ = NULL;
79 } 84 }
80 85
81 // static 86 // static
82 GtkWidget* ValidationMessageBubbleGtk::ConstructContent( 87 GtkWidget* ValidationMessageBubbleGtk::ConstructContent(
83 const string16& main_text, const string16& sub_text) { 88 const string16& main_text, const string16& sub_text) {
84 GtkWidget* icon = gtk_image_new(); 89 GtkWidget* icon = gtk_image_new();
85 gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0); 90 gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0);
86 gtk_misc_set_padding(GTK_MISC(icon), kPadding, kPadding); 91 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); 122 gtk_container_add(GTK_CONTAINER(content), icon_text_box);
118 return content; 123 return content;
119 } 124 }
120 125
121 } // namespace 126 } // namespace
122 127
123 namespace chrome { 128 namespace chrome {
124 129
125 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( 130 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
126 content::RenderWidgetHost* widget_host, 131 content::RenderWidgetHost* widget_host,
127 const gfx::Rect& anchor_in_screen, 132 const gfx::Rect& anchor_in_root_view,
128 const string16& main_text, 133 const string16& main_text,
129 const string16& sub_text) { 134 const string16& sub_text) {
130 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleGtk( 135 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleGtk(
131 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); 136 widget_host, anchor_in_root_view, main_text, sub_text)).Pass();
132 } 137 }
133 138
134 } // namespace chrome 139 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698