| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 25 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/common/chrome_features.h" | 27 #include "chrome/common/chrome_features.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 30 #include "components/omnibox/browser/vector_icons.h" | 30 #include "components/omnibox/browser/vector_icons.h" |
| 31 #include "components/prefs/pref_member.h" | 31 #include "components/prefs/pref_member.h" |
| 32 #include "components/search_engines/util.h" | 32 #include "components/search_engines/util.h" |
| 33 #include "components/strings/grit/components_strings.h" | 33 #include "components/strings/grit/components_strings.h" |
| 34 #include "components/toolbar/vector_icons.h" | 34 #include "components/toolbar/vector_icons.h" |
| 35 #include "components/url_formatter/url_formatter.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/l10n/l10n_util_mac.h" | 38 #include "ui/base/l10n/l10n_util_mac.h" |
| 38 #include "ui/gfx/color_palette.h" | 39 #include "ui/gfx/color_palette.h" |
| 39 #include "ui/gfx/color_utils.h" | 40 #include "ui/gfx/color_utils.h" |
| 40 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
| 41 #include "ui/gfx/image/image_skia_util_mac.h" | 42 #include "ui/gfx/image/image_skia_util_mac.h" |
| 42 #include "ui/gfx/paint_vector_icon.h" | 43 #include "ui/gfx/paint_vector_icon.h" |
| 43 #include "ui/vector_icons/vector_icons.h" | 44 #include "ui/vector_icons/vector_icons.h" |
| 44 | 45 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 [touchBarItem | 310 [touchBarItem |
| 310 setCustomizationLabel:l10n_util::GetNSString( | 311 setCustomizationLabel:l10n_util::GetNSString( |
| 311 IDS_TOUCH_BAR_BOOKMARK_CUSTOMIZATION_LABEL)]; | 312 IDS_TOUCH_BAR_BOOKMARK_CUSTOMIZATION_LABEL)]; |
| 312 } else if ([identifier hasSuffix:kSearchTouchId]) { | 313 } else if ([identifier hasSuffix:kSearchTouchId]) { |
| 313 [touchBarItem setView:[self searchTouchBarView]]; | 314 [touchBarItem setView:[self searchTouchBarView]]; |
| 314 [touchBarItem setCustomizationLabel:l10n_util::GetNSString( | 315 [touchBarItem setCustomizationLabel:l10n_util::GetNSString( |
| 315 IDS_TOUCH_BAR_GOOGLE_SEARCH)]; | 316 IDS_TOUCH_BAR_GOOGLE_SEARCH)]; |
| 316 } else if ([identifier hasSuffix:kFullscreenOriginLabelTouchId]) { | 317 } else if ([identifier hasSuffix:kFullscreenOriginLabelTouchId]) { |
| 317 content::WebContents* contents = | 318 content::WebContents* contents = |
| 318 browser_->tab_strip_model()->GetActiveWebContents(); | 319 browser_->tab_strip_model()->GetActiveWebContents(); |
| 319 GURL originUrl = contents->GetLastCommittedURL(); | |
| 320 | 320 |
| 321 base::string16 displayText = base::ASCIIToUTF16(originUrl.spec()); | 321 if (!contents) |
| 322 return nil; |
| 323 |
| 324 // Strip the trailing slash. |
| 325 url::Parsed parsed; |
| 326 base::string16 displayText = url_formatter::FormatUrl( |
| 327 contents->GetLastCommittedURL(), |
| 328 url_formatter::kFormatUrlOmitTrailingSlashOnBareHostname, |
| 329 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr); |
| 330 |
| 322 base::scoped_nsobject<NSMutableAttributedString> attributedString( | 331 base::scoped_nsobject<NSMutableAttributedString> attributedString( |
| 323 [[NSMutableAttributedString alloc] | 332 [[NSMutableAttributedString alloc] |
| 324 initWithString:base::SysUTF16ToNSString(displayText)]); | 333 initWithString:base::SysUTF16ToNSString(displayText)]); |
| 325 | 334 |
| 326 if (originUrl.has_path()) { | 335 if (parsed.path.is_nonempty()) { |
| 327 size_t pathIndex = originUrl.GetWithEmptyPath().spec().length(); | 336 size_t pathIndex = parsed.path.begin; |
| 328 [attributedString | 337 [attributedString |
| 329 addAttribute:NSForegroundColorAttributeName | 338 addAttribute:NSForegroundColorAttributeName |
| 330 value:OmniboxViewMac::BaseTextColor(true) | 339 value:OmniboxViewMac::BaseTextColor(true) |
| 331 range:NSMakeRange(pathIndex, | 340 range:NSMakeRange(pathIndex, |
| 332 [attributedString length] - pathIndex)]; | 341 [attributedString length] - pathIndex)]; |
| 333 } | 342 } |
| 334 | 343 |
| 335 [touchBarItem | 344 [touchBarItem |
| 336 setView:[NSTextField labelWithAttributedString:attributedString.get()]]; | 345 setView:[NSTextField labelWithAttributedString:attributedString.get()]]; |
| 337 } else if ([identifier hasSuffix:kExitFullscreenTouchId]) { | 346 } else if ([identifier hasSuffix:kExitFullscreenTouchId]) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 ->ExitExclusiveAccessIfNecessary(); | 486 ->ExitExclusiveAccessIfNecessary(); |
| 478 } | 487 } |
| 479 | 488 |
| 480 - (void)executeCommand:(id)sender { | 489 - (void)executeCommand:(id)sender { |
| 481 int command = [sender tag]; | 490 int command = [sender tag]; |
| 482 LogTouchBarUMA(command); | 491 LogTouchBarUMA(command); |
| 483 commandUpdater_->ExecuteCommand(command); | 492 commandUpdater_->ExecuteCommand(command); |
| 484 } | 493 } |
| 485 | 494 |
| 486 @end | 495 @end |
| OLD | NEW |