15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/tab_specific_content_settings.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/content_settings/content_setting_image_model.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/content_setting_bubble_contents.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/location_bar/location_bar_view.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "grit/theme_resources.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/gfx/color_utils.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/views/controls/image_view.h" 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/views/controls/label.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int kBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int kStayOpenTimeMS = 3200; // Time spent with animation fully open. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// static 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int ContentSettingImageView::kOpenTimeMS = 150; 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int ContentSettingImageView::kAnimationDurationMS = 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (kOpenTimeMS * 2) + kStayOpenTimeMS; 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentSettingImageView::ContentSettingImageView( 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentSettingsType content_type, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LocationBarView* parent, 36d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const gfx::FontList& font_list, 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColor text_color, 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColor parent_background_color) 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : parent_(parent), 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content_setting_image_model_( 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentSettingImageModel::CreateContentSettingImageModel( 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content_type)), 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) background_painter_( 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) views::Painter::CreateImageGridPainter(kBackgroundImages)), 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) icon_(new views::ImageView), 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) text_label_(new views::Label(base::string16(), font_list)), 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_(this), 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pause_animation_(false), 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pause_animation_state_(0.0), 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_(NULL) { 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) icon_->SetHorizontalAlignment(views::ImageView::LEADING); 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AddChildView(icon_); 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetVisible(false); 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetEnabledColor(text_color); 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Calculate the actual background color for the label. The background images 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // are painted atop |parent_background_color|. We grab the color of the 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // middle pixel of the middle image of the background, which we treat as the 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // representative color of the entire background (reasonable, given the 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // current appearance of these images). Then we alpha-blend it over the 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // parent background color to determine the actual color the label text will 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // sit atop. 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const SkBitmap& bitmap( 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 6568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) kBackgroundImages[4])->GetRepresentation(1.0f).sk_bitmap()); 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkAutoLockPixels pixel_lock(bitmap); 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColor background_image_color = 68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Tricky bit: We alpha blend an opaque version of |background_image_color| 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // against |parent_background_color| using the original image grid color's 71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // even if |a| is a color with non-255 alpha. 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetBackgroundColor( 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) parent_background_color, 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SkColorGetA(background_image_color))); 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) text_label_->SetElideBehavior(gfx::TRUNCATE); 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) AddChildView(text_label_); 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.SetSlideDuration(kAnimationDurationMS); 82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) slide_animator_.SetTweenType(gfx::Tween::LINEAR); 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentSettingImageView::~ContentSettingImageView() { 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (bubble_widget_) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_->RemoveObserver(this); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ContentSettingImageView::Update(content::WebContents* web_contents) { 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Note: We explicitly want to call this even if |web_contents| is NULL, so we 92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // get hidden properly while the user is editing the omnibox. 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_setting_image_model_->UpdateFromWebContents(web_contents); 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!content_setting_image_model_->is_visible()) { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetVisible(false); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) icon_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content_setting_image_model_->get_icon())); 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) icon_->SetTooltipText( 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::UTF8ToUTF16(content_setting_image_model_->get_tooltip())); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetVisible(true); 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // If the content blockage should be indicated to the user, start the 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // animation and record that we indicated the blockage. 108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) TabSpecificContentSettings* content_settings = web_contents ? 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) TabSpecificContentSettings::FromWebContents(web_contents) : NULL; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!content_settings || content_settings->IsBlockageIndicated( 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content_setting_image_model_->get_content_settings_type())) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // We just ignore this blockage if we're already showing some other string to 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // the user. If this becomes a problem, we could design some sort of queueing 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // mechanism to show one after the other, but it doesn't seem important now. 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int string_id = content_setting_image_model_->explanatory_string_id(); 118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (string_id && !background_showing()) { 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetText(l10n_util::GetStringUTF16(string_id)); 120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetVisible(true); 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.Show(); 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 12358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content_settings->SetBlockageHasBeenIndicated( 125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content_setting_image_model_->get_content_settings_type()); 12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// static 129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)int ContentSettingImageView::GetBubbleOuterPadding(bool by_icon) { 1305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return LocationBarView::kItemPadding - LocationBarView::kBubblePadding + 131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (by_icon ? 0 : LocationBarView::kIconInternalPadding); 13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { 135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.Reset(); 136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!pause_animation_) { 137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetVisible(false); 13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) parent_->Layout(); 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) parent_->SchedulePaint(); 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ContentSettingImageView::AnimationProgressed( 144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const gfx::Animation* animation) { 145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!pause_animation_) { 146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) parent_->Layout(); 147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) parent_->SchedulePaint(); 148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ContentSettingImageView::AnimationCanceled( 152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const gfx::Animation* animation) { 15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AnimationEnded(animation); 15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 156cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)gfx::Size ContentSettingImageView::GetPreferredSize() const { 157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Height will be ignored by the LocationBarView. 158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Size size(icon_->GetPreferredSize()); 159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (background_showing()) { 160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) double state = slide_animator_.GetCurrentValue(); 161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The fraction of the animation we'll spend animating the string into view, 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // which is also the fraction we'll spend animating it closed; total 163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // animation (slide out, show, then slide in) is 1.0. 164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const double kOpenFraction = 165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; 166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) double size_fraction = 1.0; 167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (state < kOpenFraction) 168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size_fraction = state / kOpenFraction; 169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (state > (1.0 - kOpenFraction)) 170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size_fraction = (1.0 - state) / kOpenFraction; 171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size.Enlarge( 172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size_fraction * (text_label_->GetPreferredSize().width() + 173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetTotalSpacingWhileAnimating()), 0); 174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size.SetToMax(background_painter_->GetMinimumSize()); 17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return size; 17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 17890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 179868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ContentSettingImageView::Layout() { 180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const int icon_width = icon_->GetPreferredSize().width(); 181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) icon_->SetBounds( 182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, 183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) icon_width, height()); 184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) text_label_->SetBounds( 1855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu icon_->bounds().right() + LocationBarView::kItemPadding, 0, 186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), 1870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) height()); 18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 19190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // We want to show the bubble on mouse release; that is the standard behavior 19290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // for buttons. 19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return true; 19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 197868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (HitTestPoint(event.location())) 198868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) OnClick(); 199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (event->type() == ui::ET_GESTURE_TAP) 203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) OnClick(); 204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if ((event->type() == ui::ET_GESTURE_TAP) || 205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (event->type() == ui::ET_GESTURE_TAP_DOWN)) 206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) event->SetHandled(); 20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { 210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (background_showing()) 211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) background_painter_->Paint(canvas, size()); 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) { 215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK_EQ(bubble_widget_, widget); 216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bubble_widget_->RemoveObserver(this); 217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bubble_widget_ = NULL; 218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (pause_animation_) { 220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.Reset(pause_animation_state_); 221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pause_animation_ = false; 222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.Show(); 223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)int ContentSettingImageView::GetTotalSpacingWhileAnimating() const { 2275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return GetBubbleOuterPadding(true) + LocationBarView::kItemPadding + 228868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetBubbleOuterPadding(false); 229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ContentSettingImageView::OnClick() { 232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (slide_animator_.is_animating()) { 233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!pause_animation_) { 234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pause_animation_ = true; 235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pause_animation_state_ = slide_animator_.GetCurrentValue(); 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) slide_animator_.Reset(); 238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) content::WebContents* web_contents = parent_->GetWebContents(); 241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (web_contents && !bubble_widget_) { 242f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bubble_widget_ = 243f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( 244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ContentSettingBubbleModel::CreateContentSettingBubbleModel( 245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) parent_->delegate()->GetContentSettingBubbleModelDelegate(), 246f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_contents, parent_->profile(), 247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content_setting_image_model_->get_content_settings_type()), 248cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_contents, this, views::BubbleBorder::TOP_RIGHT)); 249f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bubble_widget_->AddObserver(this); 250f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bubble_widget_->Show(); 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 253