OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/cocoa/tooltip_manager_mac.h" | 5 #include "ui/views/cocoa/tooltip_manager_mac.h" |
6 | 6 |
7 #include "ui/gfx/font_list.h" | 7 #include "ui/gfx/font_list.h" |
8 #import "ui/gfx/mac/coordinate_conversion.h" | 8 #import "ui/gfx/mac/coordinate_conversion.h" |
9 #import "ui/views/cocoa/bridged_content_view.h" | 9 #import "ui/views/cocoa/bridged_content_view.h" |
10 #import "ui/views/cocoa/bridged_native_widget.h" | 10 #import "ui/views/cocoa/bridged_native_widget.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Max visual tooltip width in DIPs. Beyond this, Cocoa will wrap text. | 14 // Max visual tooltip width in DIPs. Beyond this, Cocoa will wrap text. |
15 const int kTooltipMaxWidthPixels = 250; | 15 const int kTooltipMaxWidthPixels = 250; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 namespace views { | 19 namespace views { |
20 | 20 |
21 TooltipManagerMac::TooltipManagerMac(BridgedNativeWidget* widget) | 21 TooltipManagerMac::TooltipManagerMac(BridgedNativeWidget* widget) |
22 : widget_(widget) { | 22 : widget_(widget) { |
23 } | 23 } |
24 | 24 |
25 TooltipManagerMac::~TooltipManagerMac() { | 25 TooltipManagerMac::~TooltipManagerMac() { |
26 } | 26 } |
27 | 27 |
28 int TooltipManagerMac::GetMaxWidth(const gfx::Point& location, | 28 int TooltipManagerMac::GetMaxWidth(const gfx::Point& location) const { |
29 gfx::NativeView context) const { | |
30 return kTooltipMaxWidthPixels; | 29 return kTooltipMaxWidthPixels; |
31 } | 30 } |
32 | 31 |
33 const gfx::FontList& TooltipManagerMac::GetFontList() const { | 32 const gfx::FontList& TooltipManagerMac::GetFontList() const { |
34 CR_DEFINE_STATIC_LOCAL(gfx::FontList, font_list, | 33 CR_DEFINE_STATIC_LOCAL(gfx::FontList, font_list, |
35 (gfx::Font([NSFont toolTipsFontOfSize:0]))); | 34 (gfx::Font([NSFont toolTipsFontOfSize:0]))); |
36 return font_list; | 35 return font_list; |
37 } | 36 } |
38 | 37 |
39 void TooltipManagerMac::UpdateTooltip() { | 38 void TooltipManagerMac::UpdateTooltip() { |
40 NSWindow* window = widget_->ns_window(); | 39 NSWindow* window = widget_->ns_window(); |
41 BridgedContentView* view = widget_->ns_view(); | 40 BridgedContentView* view = widget_->ns_view(); |
42 | 41 |
43 NSPoint nspoint = [window convertScreenToBase:[NSEvent mouseLocation]]; | 42 NSPoint nspoint = [window convertScreenToBase:[NSEvent mouseLocation]]; |
44 // Note: flip in the view's frame, which matches the window's contentRect. | 43 // Note: flip in the view's frame, which matches the window's contentRect. |
45 gfx::Point point(nspoint.x, NSHeight([view frame]) - nspoint.y); | 44 gfx::Point point(nspoint.x, NSHeight([view frame]) - nspoint.y); |
46 [view updateTooltipIfRequiredAt:point]; | 45 [view updateTooltipIfRequiredAt:point]; |
47 } | 46 } |
48 | 47 |
49 void TooltipManagerMac::TooltipTextChanged(View* view) { | 48 void TooltipManagerMac::TooltipTextChanged(View* view) { |
50 // The intensive part is View::GetTooltipHandlerForPoint(), which will be done | 49 // The intensive part is View::GetTooltipHandlerForPoint(), which will be done |
51 // in [BridgedContentView updateTooltipIfRequiredAt:]. Don't do it here as | 50 // in [BridgedContentView updateTooltipIfRequiredAt:]. Don't do it here as |
52 // well. | 51 // well. |
53 UpdateTooltip(); | 52 UpdateTooltip(); |
54 } | 53 } |
55 | 54 |
56 } // namespace views | 55 } // namespace views |
OLD | NEW |