Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: ui/views/cocoa/tooltip_manager_mac.mm

Issue 1137653005: MacViews: Implement Tooltips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/tooltip_manager_mac.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/tooltip_manager_mac.mm
diff --git a/ui/views/cocoa/tooltip_manager_mac.mm b/ui/views/cocoa/tooltip_manager_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..b96d122771514bf05397c8326c9e482ee8311c96
--- /dev/null
+++ b/ui/views/cocoa/tooltip_manager_mac.mm
@@ -0,0 +1,56 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/cocoa/tooltip_manager_mac.h"
+
+#include "ui/gfx/font_list.h"
+#import "ui/gfx/mac/coordinate_conversion.h"
+#import "ui/views/cocoa/bridged_content_view.h"
+#import "ui/views/cocoa/bridged_native_widget.h"
+
+namespace {
+
+// Max visual tooltip width in DIPs. Beyond this, Cocoa will wrap text.
+const int kTooltipMaxWidthPixels = 250;
+
+} // namespace
+
+namespace views {
+
+TooltipManagerMac::TooltipManagerMac(BridgedNativeWidget* widget)
+ : widget_(widget) {
+}
+
+TooltipManagerMac::~TooltipManagerMac() {
+}
+
+int TooltipManagerMac::GetMaxWidth(const gfx::Point& location,
+ gfx::NativeView context) const {
+ return kTooltipMaxWidthPixels;
+}
+
+const gfx::FontList& TooltipManagerMac::GetFontList() const {
+ CR_DEFINE_STATIC_LOCAL(gfx::FontList, font_list,
+ (gfx::Font([NSFont toolTipsFontOfSize:0])));
+ return font_list;
+}
+
+void TooltipManagerMac::UpdateTooltip() {
+ NSWindow* window = widget_->ns_window();
+ BridgedContentView* view = widget_->ns_view();
+
+ NSPoint nspoint = [window convertScreenToBase:[NSEvent mouseLocation]];
+ // Note: flip in the view's frame, which matches the window's contentRect.
+ gfx::Point point(nspoint.x, NSHeight([view frame]) - nspoint.y);
+ [view updateTooltipIfRequiredAt:point];
+}
+
+void TooltipManagerMac::TooltipTextChanged(View* view) {
+ // The intensive part is View::GetTooltipHandlerForPoint(), which will be done
+ // in [BridgedContentView updateTooltipIfRequiredAt:]. Don't do it here as
+ // well.
+ UpdateTooltip();
+}
+
+} // namespace views
« no previous file with comments | « ui/views/cocoa/tooltip_manager_mac.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698