tooltip_manager_mac.mm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/views/cocoa/tooltip_manager_mac.h"
  5. #include "base/no_destructor.h"
  6. #import "components/remote_cocoa/app_shim/bridged_content_view.h"
  7. #import "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
  8. #include "ui/base/cocoa/cocoa_base_utils.h"
  9. #include "ui/gfx/font_list.h"
  10. #import "ui/gfx/mac/coordinate_conversion.h"
  11. #include "ui/gfx/platform_font_mac.h"
  12. namespace {
  13. // Max visual tooltip width in DIPs. Beyond this, Cocoa will wrap text.
  14. const int kTooltipMaxWidthPixels = 250;
  15. } // namespace
  16. namespace views {
  17. TooltipManagerMac::TooltipManagerMac(
  18. remote_cocoa::mojom::NativeWidgetNSWindow* bridge)
  19. : bridge_(bridge) {}
  20. TooltipManagerMac::~TooltipManagerMac() {
  21. }
  22. int TooltipManagerMac::GetMaxWidth(const gfx::Point& location) const {
  23. return kTooltipMaxWidthPixels;
  24. }
  25. const gfx::FontList& TooltipManagerMac::GetFontList() const {
  26. static base::NoDestructor<gfx::FontList> font_list([]() {
  27. return gfx::Font(new gfx::PlatformFontMac(
  28. gfx::PlatformFontMac::SystemFontType::kToolTip));
  29. }());
  30. return *font_list;
  31. }
  32. void TooltipManagerMac::UpdateTooltip() {
  33. bridge_->UpdateTooltip();
  34. }
  35. void TooltipManagerMac::TooltipTextChanged(View* view) {
  36. // The intensive part is View::GetTooltipHandlerForPoint(), which will be done
  37. // in [BridgedContentView updateTooltipIfRequiredAt:]. Don't do it here as
  38. // well.
  39. UpdateTooltip();
  40. }
  41. } // namespace views