Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/views/toolbar/site_chip_view.h" | 5 #include "chrome/browser/ui/views/toolbar/site_chip_view.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | |
| 7 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/extensions/extension_icon_image.h" | |
| 13 #include "chrome/browser/extensions/extension_service.h" | |
| 14 #include "chrome/browser/extensions/extension_system.h" | |
| 15 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/browser/themes/theme_properties.h" | 18 #include "chrome/browser/themes/theme_properties.h" |
| 13 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 20 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 22 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 23 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 24 #include "chrome/common/extensions/extension_constants.h" | |
| 25 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | |
| 18 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "extensions/common/constants.h" | |
| 20 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 21 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/base/theme_provider.h" | 32 #include "ui/base/theme_provider.h" |
| 24 #include "ui/views/background.h" | 33 #include "ui/views/background.h" |
| 34 #include "ui/views/button_drag_utils.h" | |
| 25 #include "ui/views/controls/button/label_button.h" | 35 #include "ui/views/controls/button/label_button.h" |
| 26 #include "ui/views/controls/button/label_button_border.h" | 36 #include "ui/views/controls/button/label_button_border.h" |
| 27 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/painter.h" | 38 #include "ui/views/painter.h" |
| 29 | 39 |
| 30 const int kEdgeThickness = 4; | 40 const int kEdgeThickness = 4; |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Anonymous-namespace these and move them to th
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 41 const int k16x16IconExtraSpacing = 3; | |
| 31 const int kIconTextSpacing = 4; | 42 const int kIconTextSpacing = 4; |
| 32 const int kTrailingLabelMargin = 2; | 43 const int kTrailingLabelMargin = 2; |
| 33 | 44 |
| 45 class SiteChipExtensionIcon : public extensions::IconImage::Observer { | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Add a // SiteChipExtensionIcon ----... divide
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 46 public: | |
| 47 SiteChipExtensionIcon(LocationIconView* icon_view, | |
| 48 Profile* profile, | |
| 49 const extensions::Extension* extension) | |
| 50 : icon_view_(icon_view) { | |
|
Peter Kasting
2013/12/06 02:16:52
Don't inline definitions into the class declaratio
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 51 icon_image_.reset(new extensions::IconImage( | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Avoid reset() call by initing this in the ini
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 52 profile, | |
| 53 extension, | |
| 54 extensions::IconsInfo::GetIcons(extension), | |
| 55 extension_misc::EXTENSION_ICON_BITTY, | |
| 56 extensions::IconsInfo::GetDefaultAppIcon(), | |
| 57 this)); | |
| 58 icon_image_->image_skia().GetRepresentation(1.0f); | |
| 59 | |
| 60 if (icon_image_->image_skia().image_reps().size() > 0) | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Use !empty()
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 61 icon_view_->SetImage(&(icon_image_->image_skia())); | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Call OnExtensionIconImageChanged() instead.
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 62 } | |
| 63 | |
| 64 ~SiteChipExtensionIcon() { | |
| 65 icon_view_ = NULL; | |
| 66 icon_image_.reset(); | |
|
Peter Kasting
2013/12/06 02:16:52
Why are we doing either of these?
Greg Billock
2013/12/06 19:54:26
I hunted through the IconImage code for a while tr
| |
| 67 } | |
| 68 | |
| 69 // IconImage::Observer: | |
| 70 virtual void OnExtensionIconImageChanged( | |
| 71 extensions::IconImage* image) OVERRIDE { | |
| 72 if (icon_view_) | |
| 73 icon_view_->SetImage(&(icon_image_->image_skia())); | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Are the innermost parens necessary? Normally
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 scoped_ptr<extensions::IconImage> icon_image_; | |
| 78 LocationIconView* icon_view_; | |
| 79 }; | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: DISALLOW_COPY_AND_ASSIGN
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 80 | |
| 81 string16 HostnameFromURL(const GURL& url, Profile* profile) { | |
|
Peter Kasting
2013/12/06 02:16:52
This function name is misleading. We're not neces
Greg Billock
2013/12/06 19:54:26
Renamed.
On 2013/12/06 02:16:52, Peter Kasting wr
| |
| 82 // The NTP. | |
| 83 if (!url.is_valid()) { | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: No {}
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 84 return string16(UTF8ToUTF16("Chrome")); | |
|
Peter Kasting
2013/12/06 02:16:52
Thought we were doing "New Tab" here.
Also, the e
Greg Billock
2013/12/06 19:54:26
I have a TODO here below -- If we use the page nam
| |
| 85 } | |
| 86 | |
| 87 // TODO(gbillock): for kChromeUIScheme and kAboutScheme, return the title of | |
| 88 // the page. | |
| 89 // See url_constants.cc for hosts. ?? Or just show "Chrome"? | |
| 90 if (url.SchemeIs(chrome::kChromeUIScheme) || | |
| 91 url.SchemeIs(chrome::kAboutScheme)) { | |
| 92 return string16(UTF8ToUTF16("Chrome")); | |
| 93 } | |
| 94 | |
| 95 | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Extra blank line
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 96 // For file: urls, return the BaseName of the file . | |
|
Peter Kasting
2013/12/06 02:16:52
That seems wrong. I'd expect to see the whole fil
Greg Billock
2013/12/06 19:54:26
I'm not sure what the use case is. If its basicall
| |
| 97 if (url.SchemeIsFile()) { | |
| 98 base::FilePath path = base::FilePath::FromUTF8Unsafe(url.path()); | |
| 99 // TODO(gbillock): Need nuance here. | |
| 100 return string16(base::UTF8ToUTF16(path.BaseName().value())); | |
| 101 } | |
| 102 | |
| 103 // TODO(gbillock): Handle filesystem urls the same way? | |
| 104 // Also: should handle interstitials differently? | |
| 105 | |
| 106 // TODO(gbillock): think about view-source? | |
|
Peter Kasting
2013/12/06 02:16:52
Normally we'd strip the view-source: part and then
Greg Billock
2013/12/06 19:54:26
ack. Leaving as TODO for now.
| |
| 107 | |
| 108 // For chrome-extension urls, return the extension name. | |
| 109 if (url.SchemeIs(extensions::kExtensionScheme)) { | |
| 110 ExtensionService* service = | |
| 111 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 112 if (!service) | |
|
Peter Kasting
2013/12/06 02:16:52
Can this actually fail? Maybe in tests?
Greg Billock
2013/12/06 19:54:26
Yeah, this should never fail in production. I don'
| |
| 113 return string16(base::UTF8ToUTF16(url.host())); | |
| 114 | |
| 115 const extensions::Extension* extension = | |
| 116 service->extensions()->GetExtensionOrAppByURL(url); | |
| 117 if (!extension) | |
| 118 return string16(UTF8ToUTF16(url.host())); | |
| 119 return string16(base::UTF8ToUTF16(extension->name())); | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Shorter:
return base::UTF8ToUTF16(extensio
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 120 } | |
| 121 | |
| 122 if (url.SchemeIsHTTPOrHTTPS()) { | |
| 123 // See ToolbarModelImpl::GetText(). Does not pay attention to any user | |
| 124 // edits, and uses GetURL/net::FormatUrl -- We don't really care about | |
| 125 // length or the autocomplete parser. | |
|
Peter Kasting
2013/12/06 02:16:52
This whole section is way too complicated for what
Greg Billock
2013/12/06 19:54:26
I'm worried about i18n domain names and other unic
Peter Kasting
2013/12/06 21:26:11
That's fair. It seems like in that case though we
Greg Billock
2013/12/06 22:11:50
FormatUrl calls through a couple layers internally
| |
| 126 std::string languages; | |
| 127 if (profile) | |
| 128 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
| 129 | |
| 130 base::string16 formatted = net::FormatUrl(url.GetOrigin(), languages, | |
| 131 net::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, NULL, NULL, NULL); | |
| 132 // Remove scheme, "www.", and trailing "/". | |
| 133 if (StartsWith(formatted, ASCIIToUTF16("http://"), false)) | |
| 134 formatted = formatted.substr(7); | |
| 135 if (StartsWith(formatted, ASCIIToUTF16("https://"), false)) | |
| 136 formatted = formatted.substr(8); | |
| 137 if (StartsWith(formatted, ASCIIToUTF16("www."), false)) | |
| 138 formatted = formatted.substr(4); | |
| 139 if (EndsWith(formatted, ASCIIToUTF16("/"), false)) | |
| 140 formatted = formatted.substr(0, formatted.size()-1); | |
| 141 return formatted; | |
| 142 } | |
| 143 | |
| 144 // For FTP, prepend "ftp:" to hostname. | |
|
Peter Kasting
2013/12/06 02:16:52
We should treat this like HTTP/HTTPS. Prepending
Greg Billock
2013/12/06 19:54:26
I'm not sure where this originated -- it's in the
| |
| 145 if (url.SchemeIs(content::kFtpScheme)) { | |
| 146 return string16(UTF8ToUTF16(std::string("ftp:") + url.host())); | |
| 147 } | |
| 148 | |
| 149 // If all else fails, return hostname. | |
| 150 return string16(UTF8ToUTF16(url.host())); | |
|
Peter Kasting
2013/12/06 02:16:52
Just remove the scheme check above and let that co
Greg Billock
2013/12/06 19:54:26
Let's figure out whether we need net::FormatUrl fi
| |
| 151 } | |
| 152 | |
| 34 SiteChipView::SiteChipView(ToolbarView* toolbar_view) | 153 SiteChipView::SiteChipView(ToolbarView* toolbar_view) |
| 35 : ToolbarButton(this, NULL), | 154 : ToolbarButton(this, NULL), |
| 36 toolbar_view_(toolbar_view) { | 155 toolbar_view_(toolbar_view), |
| 156 showing_16x16_icon_(false) { | |
| 157 set_drag_controller(this); | |
| 37 } | 158 } |
| 38 | 159 |
| 39 SiteChipView::~SiteChipView() { | 160 SiteChipView::~SiteChipView() { |
| 161 extension_icon_loader_.reset(); | |
|
Peter Kasting
2013/12/06 02:16:52
Why does this need to be done explicitly?
Greg Billock
2013/12/06 19:54:26
I don't like leaving the icon fetch to clean itsel
Peter Kasting
2013/12/06 21:26:11
I don't understand your comment here or in ~SiteCh
Greg Billock
2013/12/06 22:11:50
Agreed. I got gunshy after getting unexpected cras
| |
| 40 } | 162 } |
| 41 | 163 |
| 42 void SiteChipView::Init() { | 164 void SiteChipView::Init() { |
| 43 ToolbarButton::Init(); | 165 ToolbarButton::Init(); |
| 44 | 166 |
| 45 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. | 167 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. |
| 46 location_icon_view_ = new LocationIconView(toolbar_view_->location_bar()); | 168 location_icon_view_ = new LocationIconView(toolbar_view_->location_bar()); |
| 47 host_label_ = new views::Label(); | 169 host_label_ = new views::Label(); |
| 48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 170 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 49 host_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 171 host_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 50 | 172 |
| 51 AddChildView(location_icon_view_); | 173 AddChildView(location_icon_view_); |
| 52 AddChildView(host_label_); | 174 AddChildView(host_label_); |
| 53 | 175 |
| 54 // temporary background painter | |
| 55 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV); | |
| 56 background_painter_.reset( | |
| 57 views::Painter::CreateImageGridPainter(kBackgroundImages)); | |
| 58 | |
| 59 // temporary icon filler | |
| 60 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( | 176 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( |
| 61 IDR_OMNIBOX_HTTPS_VALID)); | 177 IDR_LOCATION_BAR_HTTP)); |
| 62 location_icon_view_->ShowTooltip(true); | 178 location_icon_view_->ShowTooltip(true); |
| 63 | |
| 64 // temporary filler text. | |
| 65 host_label_->SetText(ASCIIToUTF16("site.chip")); | |
| 66 } | 179 } |
| 67 | 180 |
| 68 bool SiteChipView::ShouldShow() { | 181 bool SiteChipView::ShouldShow() { |
| 69 return chrome::ShouldDisplayOriginChip(); | 182 return chrome::ShouldDisplayOriginChip(); |
| 70 } | 183 } |
| 71 | 184 |
| 72 void SiteChipView::Update(content::WebContents* tab) { | 185 void SiteChipView::Update(content::WebContents* tab) { |
|
Peter Kasting
2013/12/06 02:16:52
Nit: While here: This should be named |web_content
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 186 if (!tab) | |
| 187 return; | |
| 188 | |
| 189 // Note: security level can change async as the connection is made. | |
| 190 GURL url = toolbar_view_->GetToolbarModel()->GetURL(); | |
| 191 const ToolbarModel::SecurityLevel security_level = | |
| 192 toolbar_view_->GetToolbarModel()->GetSecurityLevel(true); | |
| 193 if (url == url_displayed_ && security_level == security_level_) | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: Parens around binary subexprs (several places
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 194 return; | |
| 195 | |
| 196 url_displayed_ = url; | |
| 197 | |
| 198 string16 host = HostnameFromURL(url, toolbar_view_->browser()->profile()); | |
| 199 | |
| 200 if (security_level != security_level_ && | |
| 201 security_level == ToolbarModel::EV_SECURE) { | |
|
Peter Kasting
2013/12/06 02:16:52
Nit: No {}
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 202 host = toolbar_view_->GetToolbarModel()->GetEVCertName(); | |
| 203 } | |
| 204 | |
| 205 host_ = host; | |
| 206 host_label_->SetText(host_); | |
| 207 host_label_->SetTooltipText(host_); | |
| 208 // TODO(gbillock): do better than this: goal is to use black unless | |
| 209 // it'd be too low contrast, then switch to ?? inverse? | |
|
Peter Kasting
2013/12/06 02:16:52
Yeah, so what's the problem? That seems to be wha
Greg Billock
2013/12/06 19:54:26
stale comment, I ended up just doing this but didn
| |
| 210 SkColor toolbar_background = | |
| 211 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR); | |
| 212 SkColor host_color = | |
| 213 color_utils::GetReadableColor(SK_ColorBLACK, toolbar_background); | |
| 214 host_label_->SetEnabledColor(host_color); | |
| 215 | |
| 216 security_level_ = security_level; | |
| 217 // See ToolbarModelImpl::GetIcon() | |
|
Peter Kasting
2013/12/06 02:16:52
Instead of copying parts of that code here can we
Greg Billock
2013/12/06 19:54:26
I'm not sure why this icon is calculated in so dis
Peter Kasting
2013/12/06 21:26:11
It doesn't look that bad -- it looks like GetIcon(
Greg Billock
2013/12/06 22:11:50
I'll give it a shot. I'm trying to prioritize keep
Greg Billock
2013/12/06 22:42:41
Sent you a CL under separate cover to create this
| |
| 218 static int icon_ids[ToolbarModel::NUM_SECURITY_LEVELS] = { | |
| 219 IDR_LOCATION_BAR_HTTP, | |
| 220 IDR_OMNIBOX_HTTPS_VALID, | |
| 221 IDR_OMNIBOX_HTTPS_VALID, | |
| 222 IDR_OMNIBOX_HTTPS_WARNING, | |
| 223 IDR_OMNIBOX_HTTPS_POLICY_WARNING, | |
| 224 IDR_OMNIBOX_HTTPS_INVALID, | |
| 225 }; | |
| 226 DCHECK(arraysize(icon_ids) == ToolbarModel::NUM_SECURITY_LEVELS); | |
| 227 int icon = icon_ids[security_level]; | |
| 228 showing_16x16_icon_ = false; | |
| 229 | |
| 230 if (!url.is_valid() || | |
| 231 url.SchemeIs(chrome::kChromeUIScheme)) { | |
| 232 icon = IDR_PRODUCT_LOGO_16; | |
| 233 showing_16x16_icon_ = true; | |
| 234 } | |
| 235 | |
| 236 if (url.SchemeIs(extensions::kExtensionScheme)) { | |
| 237 icon = IDR_EXTENSIONS_FAVICON; | |
| 238 showing_16x16_icon_ = true; | |
| 239 | |
| 240 ExtensionService* service = | |
| 241 extensions::ExtensionSystem::Get( | |
| 242 toolbar_view_->browser()->profile())->extension_service(); | |
| 243 if (service) { | |
|
Peter Kasting
2013/12/06 02:16:52
Again, when can this fail?
Greg Billock
2013/12/06 19:54:26
Done.
| |
| 244 const extensions::Extension* extension = | |
| 245 service->extensions()->GetExtensionOrAppByURL(url); | |
| 246 extension_icon_loader_.reset( | |
| 247 new SiteChipExtensionIcon(location_icon_view_, | |
| 248 toolbar_view_->browser()->profile(), | |
| 249 extension)); | |
| 250 } | |
| 251 } else { | |
| 252 extension_icon_loader_.reset(); | |
| 253 } | |
| 254 | |
| 255 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon)); | |
| 256 location_icon_view_->ShowTooltip(true); | |
| 257 | |
| 258 if (security_level_ == ToolbarModel::EV_SECURE) { | |
| 259 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV); | |
| 260 background_painter_.reset( | |
| 261 views::Painter::CreateImageGridPainter(kBackgroundImages)); | |
|
Peter Kasting
2013/12/06 02:16:52
Recreating these painters from scratch on every ch
Greg Billock
2013/12/06 19:54:26
Yeah, it's kind of painful. I'll make special-purp
| |
| 262 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) { | |
| 263 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_BROKENSSL); | |
| 264 background_painter_.reset( | |
| 265 views::Painter::CreateImageGridPainter(kBackgroundImages)); | |
| 266 } else { | |
| 267 // TODO(gbillock): Add malware accounting. | |
| 268 background_painter_.reset(); | |
| 269 } | |
| 270 | |
| 73 Layout(); | 271 Layout(); |
| 74 SchedulePaint(); | 272 SchedulePaint(); |
| 273 // TODO(gbillock): Need to schedule paint on parent to erase any background? | |
| 274 } | |
| 275 | |
| 276 void SiteChipView::OnChanged() { | |
| 277 Update(toolbar_view_->GetWebContents()); | |
| 278 toolbar_view_->Layout(); | |
| 279 toolbar_view_->SchedulePaint(); | |
| 280 // TODO(gbillock): Also need to potentially redo infobars. | |
|
Peter Kasting
2013/12/06 02:16:52
Why?
Greg Billock
2013/12/06 19:54:26
The layout of the site chip can change depending o
Peter Kasting
2013/12/06 21:26:11
I would ask the UI leads about this and consider p
Greg Billock
2013/12/06 22:11:50
will do.
| |
| 75 } | 281 } |
| 76 | 282 |
| 77 gfx::Size SiteChipView::GetPreferredSize() { | 283 gfx::Size SiteChipView::GetPreferredSize() { |
| 78 gfx::Size label_size = host_label_->GetPreferredSize(); | 284 gfx::Size label_size = host_label_->GetPreferredSize(); |
| 79 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); | 285 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); |
| 80 return gfx::Size(icon_size.width() + label_size.width() + | 286 return gfx::Size(icon_size.width() + label_size.width() + |
| 81 kIconTextSpacing + kTrailingLabelMargin + | 287 kIconTextSpacing + kTrailingLabelMargin + |
| 82 2 * kEdgeThickness, | 288 2 * kEdgeThickness + |
| 289 (showing_16x16_icon_ ? 2 * k16x16IconExtraSpacing : 0), | |
|
Peter Kasting
2013/12/06 02:16:52
The whole point of the spacing we set up before wa
Greg Billock
2013/12/06 19:54:26
Let's talk to Alan about this. The location icons
Peter Kasting
2013/12/06 21:26:11
I haven't seen that comment.
| |
| 83 icon_size.height()); | 290 icon_size.height()); |
| 84 } | 291 } |
| 85 | 292 |
| 86 void SiteChipView::Layout() { | 293 void SiteChipView::Layout() { |
| 294 // TODO(gbillock): Eventually we almost certainly want to use | |
| 295 // LocationBarLayout for leading and trailing decorations. | |
| 296 | |
| 87 location_icon_view_->SetBounds( | 297 location_icon_view_->SetBounds( |
| 88 kEdgeThickness, | 298 kEdgeThickness + (showing_16x16_icon_ ? k16x16IconExtraSpacing : 0), |
| 89 LocationBarView::kNormalEdgeThickness, | 299 LocationBarView::kNormalEdgeThickness, |
| 90 location_icon_view_->GetPreferredSize().width(), | 300 location_icon_view_->GetPreferredSize().width(), |
| 91 height() - 2 * LocationBarView::kNormalEdgeThickness); | 301 height() - 2 * LocationBarView::kNormalEdgeThickness); |
| 92 | 302 |
| 93 int host_label_x = location_icon_view_->x() + location_icon_view_->width() + | 303 int host_label_x = location_icon_view_->x() + location_icon_view_->width() + |
| 94 kIconTextSpacing; | 304 (showing_16x16_icon_ ? k16x16IconExtraSpacing : 0) + kIconTextSpacing; |
| 95 int host_label_width = | 305 int host_label_width = |
| 96 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; | 306 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; |
| 97 host_label_->SetBounds(host_label_x, | 307 host_label_->SetBounds(host_label_x, |
| 98 LocationBarView::kNormalEdgeThickness, | 308 LocationBarView::kNormalEdgeThickness, |
| 99 host_label_width, | 309 host_label_width, |
| 100 height() - 2 * LocationBarView::kNormalEdgeThickness); | 310 height() - 2 * LocationBarView::kNormalEdgeThickness); |
| 101 } | 311 } |
| 102 | 312 |
| 103 void SiteChipView::OnPaint(gfx::Canvas* canvas) { | 313 void SiteChipView::OnPaint(gfx::Canvas* canvas) { |
| 104 gfx::Rect rect(GetLocalBounds()); | 314 gfx::Rect rect(GetLocalBounds()); |
| 105 rect.Inset(LocationBarView::kNormalEdgeThickness, | 315 rect.Inset(LocationBarView::kNormalEdgeThickness, |
| 106 LocationBarView::kNormalEdgeThickness); | 316 LocationBarView::kNormalEdgeThickness); |
| 107 if (background_painter_.get()) | 317 if (background_painter_.get()) |
| 108 views::Painter::PaintPainterAt(canvas, background_painter_.get(), rect); | 318 views::Painter::PaintPainterAt(canvas, background_painter_.get(), rect); |
| 109 | 319 |
| 110 ToolbarButton::OnPaint(canvas); | 320 ToolbarButton::OnPaint(canvas); |
| 111 } | 321 } |
| 112 | 322 |
| 113 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for | 323 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for |
| 114 // this button. | 324 // this button. |
| 115 void SiteChipView::ButtonPressed(views::Button* sender, | 325 void SiteChipView::ButtonPressed(views::Button* sender, |
| 116 const ui::Event& event) { | 326 const ui::Event& event) { |
| 117 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus(); | 327 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus(); |
| 118 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true); | 328 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true); |
| 119 toolbar_view_->location_bar()->GetOmniboxView()->model()-> | 329 toolbar_view_->location_bar()->GetOmniboxView()->model()-> |
| 120 SetCaretVisibility(true); | 330 SetCaretVisibility(true); |
| 121 } | 331 } |
| 332 | |
| 333 void SiteChipView::WriteDragDataForView(View* sender, | |
| 334 const gfx::Point& press_pt, | |
| 335 OSExchangeData* data) { | |
| 336 content::WebContents* web_contents = toolbar_view_->GetWebContents(); | |
| 337 FaviconTabHelper* favicon_tab_helper = | |
| 338 FaviconTabHelper::FromWebContents(web_contents); | |
| 339 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); | |
| 340 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), | |
| 341 web_contents->GetTitle(), | |
| 342 favicon, | |
| 343 data, | |
| 344 sender->GetWidget()); | |
|
Peter Kasting
2013/12/06 02:16:52
It seems like this ought to be the same data the o
Greg Billock
2013/12/06 19:54:26
This is basically copy-pasted from the drag suppor
Peter Kasting
2013/12/06 21:26:11
Still seems like until then we could make this a s
Greg Billock
2013/12/06 22:11:50
:-) I hear you. I guess my intuition is that this
| |
| 345 } | |
| 346 | |
| 347 int SiteChipView::GetDragOperationsForView(View* sender, | |
| 348 const gfx::Point& p) { | |
| 349 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | |
| 350 } | |
| 351 | |
| 352 bool SiteChipView::CanStartDragForView(View* sender, | |
| 353 const gfx::Point& press_pt, | |
| 354 const gfx::Point& p) { | |
| 355 return true; | |
| 356 } | |
| 357 | |
| OLD | NEW |