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

Side by Side Diff: chrome/browser/ui/views/location_bar/content_setting_image_view.cc

Issue 8603010: content settings bubble using new ui/views/bubble api. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/content_setting_image_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/views/location_bar/content_setting_image_view.h" 5 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 ContentSettingImageView::ContentSettingImageView( 47 ContentSettingImageView::ContentSettingImageView(
48 ContentSettingsType content_type, 48 ContentSettingsType content_type,
49 LocationBarView* parent) 49 LocationBarView* parent)
50 : ui::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL), 50 : ui::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL),
51 content_setting_image_model_( 51 content_setting_image_model_(
52 ContentSettingImageModel::CreateContentSettingImageModel( 52 ContentSettingImageModel::CreateContentSettingImageModel(
53 content_type)), 53 content_type)),
54 parent_(parent), 54 parent_(parent),
55 bubble_(NULL),
56 animation_in_progress_(false), 55 animation_in_progress_(false),
57 text_size_(0), 56 text_size_(0),
58 visible_text_size_(0) { 57 visible_text_size_(0) {
59 SetHorizontalAlignment(ImageView::LEADING); 58 SetHorizontalAlignment(ImageView::LEADING);
60 } 59 }
61 60
62 ContentSettingImageView::~ContentSettingImageView() { 61 ContentSettingImageView::~ContentSettingImageView() {
63 if (bubble_)
64 bubble_->Close();
65 } 62 }
66 63
67 void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) { 64 void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) {
68 content_setting_image_model_->UpdateFromTabContents(tab_contents); 65 content_setting_image_model_->UpdateFromTabContents(tab_contents);
69 if (!content_setting_image_model_->is_visible()) { 66 if (!content_setting_image_model_->is_visible()) {
70 SetVisible(false); 67 SetVisible(false);
71 return; 68 return;
72 } 69 }
73 SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( 70 SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed(
74 content_setting_image_model_->get_icon())); 71 content_setting_image_model_->get_icon()));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 121 }
125 122
126 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { 123 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) {
127 if (!HitTest(event.location())) 124 if (!HitTest(event.location()))
128 return; 125 return;
129 126
130 TabContentsWrapper* tab_contents = parent_->GetTabContentsWrapper(); 127 TabContentsWrapper* tab_contents = parent_->GetTabContentsWrapper();
131 if (!tab_contents) 128 if (!tab_contents)
132 return; 129 return;
133 130
134 gfx::Rect screen_bounds(GetImageBounds());
135 gfx::Point origin(screen_bounds.origin());
136 views::View::ConvertPointToScreen(this, &origin);
137 screen_bounds.set_origin(origin);
138 Profile* profile = parent_->browser()->profile(); 131 Profile* profile = parent_->browser()->profile();
139 ContentSettingBubbleContents* bubble_contents = 132 ContentSettingBubbleContents* bubble = new ContentSettingBubbleContents(
140 new ContentSettingBubbleContents( 133 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
141 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 134 parent_->browser(),
142 parent_->browser(), tab_contents, profile, 135 tab_contents,
143 content_setting_image_model_->get_content_settings_type()), 136 profile,
144 profile, tab_contents->tab_contents()); 137 content_setting_image_model_->get_content_settings_type()),
145 bubble_ = Bubble::Show(GetWidget(), screen_bounds, 138 profile,
146 views::BubbleBorder::TOP_RIGHT, 139 tab_contents->tab_contents(),
147 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, 140 this,
148 bubble_contents, this); 141 views::BubbleBorder::TOP_RIGHT);
149 bubble_contents->set_bubble(bubble_); 142 views::BubbleDelegateView::CreateBubble(bubble);
150 } 143 bubble->Show();
151
152 void ContentSettingImageView::VisibilityChanged(View* starting_from,
153 bool is_visible) {
154 if (!is_visible && bubble_)
155 bubble_->Close();
156 } 144 }
157 145
158 void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) { 146 void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) {
159 gfx::Insets current_insets; 147 gfx::Insets current_insets;
160 if (border()) 148 if (border())
161 border()->GetInsets(&current_insets); 149 border()->GetInsets(&current_insets);
162 // During the animation we draw a border, an icon and the text. The text area 150 // During the animation we draw a border, an icon and the text. The text area
163 // is changing in size during the animation, giving the appearance of the text 151 // is changing in size during the animation, giving the appearance of the text
164 // sliding out and then back in. When the text completely slid out the yellow 152 // sliding out and then back in. When the text completely slid out the yellow
165 // border is no longer painted around the icon. |visible_text_size_| is 0 when 153 // border is no longer painted around the icon. |visible_text_size_| is 0 when
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 kBoxCornerRadius, paint); 195 kBoxCornerRadius, paint);
208 SkPaint outer_paint; 196 SkPaint outer_paint;
209 outer_paint.setStyle(SkPaint::kStroke_Style); 197 outer_paint.setStyle(SkPaint::kStroke_Style);
210 outer_paint.setColor(kBorderColor); 198 outer_paint.setColor(kBorderColor);
211 color_rect.inset(SkIntToScalar(kEdgeThickness), 199 color_rect.inset(SkIntToScalar(kEdgeThickness),
212 SkIntToScalar(kEdgeThickness)); 200 SkIntToScalar(kEdgeThickness));
213 canvas->GetSkCanvas()->drawRoundRect(color_rect, kBoxCornerRadius, 201 canvas->GetSkCanvas()->drawRoundRect(color_rect, kBoxCornerRadius,
214 kBoxCornerRadius, outer_paint); 202 kBoxCornerRadius, outer_paint);
215 } 203 }
216 204
217 void ContentSettingImageView::BubbleClosing(Bubble* bubble,
218 bool closed_by_escape) {
219 bubble_ = NULL;
220 }
221
222 bool ContentSettingImageView::CloseOnEscape() {
223 return true;
224 }
225
226 bool ContentSettingImageView::FadeInOnShow() {
227 return false;
228 }
229
230 void ContentSettingImageView::AnimateToState(double state) { 205 void ContentSettingImageView::AnimateToState(double state) {
231 if (state >= 1.0) { 206 if (state >= 1.0) {
232 // Animaton is over, clear the variables. 207 // Animaton is over, clear the variables.
233 animation_in_progress_ = false; 208 animation_in_progress_ = false;
234 visible_text_size_ = 0; 209 visible_text_size_ = 0;
235 } else if (state < kAnimatingFraction) { 210 } else if (state < kAnimatingFraction) {
236 visible_text_size_ = static_cast<int>(text_size_ * state / 211 visible_text_size_ = static_cast<int>(text_size_ * state /
237 kAnimatingFraction); 212 kAnimatingFraction);
238 } else if (state > (1.0 - kAnimatingFraction)) { 213 } else if (state > (1.0 - kAnimatingFraction)) {
239 visible_text_size_ = static_cast<int>(text_size_ * (1.0 - state) / 214 visible_text_size_ = static_cast<int>(text_size_ * (1.0 - state) /
240 kAnimatingFraction); 215 kAnimatingFraction);
241 } else { 216 } else {
242 visible_text_size_ = text_size_; 217 visible_text_size_ = text_size_;
243 } 218 }
244 parent_->Layout(); 219 parent_->Layout();
245 parent_->SchedulePaint(); 220 parent_->SchedulePaint();
246 } 221 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/content_setting_image_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698