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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_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 unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 BrowserAccessibilityCocoa* focused_item_cocoa = 2742 BrowserAccessibilityCocoa* focused_item_cocoa =
2743 focused_item->ToBrowserAccessibilityCocoa(); 2743 focused_item->ToBrowserAccessibilityCocoa();
2744 DCHECK(focused_item_cocoa); 2744 DCHECK(focused_item_cocoa);
2745 if (focused_item_cocoa) 2745 if (focused_item_cocoa)
2746 return focused_item_cocoa; 2746 return focused_item_cocoa;
2747 } 2747 }
2748 } 2748 }
2749 return [super accessibilityFocusedUIElement]; 2749 return [super accessibilityFocusedUIElement];
2750 } 2750 }
2751 2751
2752 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm
2753 // with minor modifications for code style and commenting.
2754 //
2755 // The 'public' interface is -setToolTipAtMousePoint:. This differs from
2756 // -setToolTip: in that the updated tooltip takes effect immediately,
2757 // without the user's having to move the mouse out of and back into the view.
2758 //
2759 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to
2760 // the view, which in turn requires overriding some internal tracking-rect
2761 // methods (to keep track of its owner & userdata, which need to be filled out
2762 // in the fake events.) --snej 7/6/09
2763
2764
2765 /*
2766 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
2767 * (C) 2006, 2007 Graham Dennis (graham.dennis@gmail.com)
2768 *
2769 * Redistribution and use in source and binary forms, with or without
2770 * modification, are permitted provided that the following conditions
2771 * are met:
2772 *
2773 * 1. Redistributions of source code must retain the above copyright
2774 * notice, this list of conditions and the following disclaimer.
2775 * 2. Redistributions in binary form must reproduce the above copyright
2776 * notice, this list of conditions and the following disclaimer in the
2777 * documentation and/or other materials provided with the distribution.
2778 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
2779 * its contributors may be used to endorse or promote products derived
2780 * from this software without specific prior written permission.
2781 *
2782 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
2783 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2784 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2785 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
2786 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2787 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2788 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2789 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2790 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2791 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2792 */
2793
2794 // Any non-zero value will do, but using something recognizable might help us
2795 // debug some day.
2796 static const NSTrackingRectTag kTrackingRectTag = 0xBADFACE;
2797
2798 // Override of a public NSView method, replacing the inherited functionality.
2799 // See above for rationale.
2800 - (NSTrackingRectTag)addTrackingRect:(NSRect)rect
2801 owner:(id)owner
2802 userData:(void *)data
2803 assumeInside:(BOOL)assumeInside {
2804 DCHECK(trackingRectOwner_ == nil);
2805 trackingRectOwner_ = owner;
2806 trackingRectUserData_ = data;
2807 return kTrackingRectTag;
2808 }
2809
2810 // Override of (apparently) a private NSView method(!) See above for rationale.
2811 - (NSTrackingRectTag)_addTrackingRect:(NSRect)rect
2812 owner:(id)owner
2813 userData:(void *)data
2814 assumeInside:(BOOL)assumeInside
2815 useTrackingNum:(int)tag {
2816 DCHECK(tag == 0 || tag == kTrackingRectTag);
2817 DCHECK(trackingRectOwner_ == nil);
2818 trackingRectOwner_ = owner;
2819 trackingRectUserData_ = data;
2820 return kTrackingRectTag;
2821 }
2822
2823 // Override of (apparently) a private NSView method(!) See above for rationale.
2824 - (void)_addTrackingRects:(NSRect *)rects
2825 owner:(id)owner
2826 userDataList:(void **)userDataList
2827 assumeInsideList:(BOOL *)assumeInsideList
2828 trackingNums:(NSTrackingRectTag *)trackingNums
2829 count:(int)count {
2830 DCHECK(count == 1);
2831 DCHECK(trackingNums[0] == 0 || trackingNums[0] == kTrackingRectTag);
2832 DCHECK(trackingRectOwner_ == nil);
2833 trackingRectOwner_ = owner;
2834 trackingRectUserData_ = userDataList[0];
2835 trackingNums[0] = kTrackingRectTag;
2836 }
2837
2838 // Override of a public NSView method, replacing the inherited functionality.
2839 // See above for rationale.
2840 - (void)removeTrackingRect:(NSTrackingRectTag)tag {
2841 if (tag == 0)
2842 return;
2843
2844 if (tag == kTrackingRectTag) {
2845 trackingRectOwner_ = nil;
2846 return;
2847 }
2848
2849 if (tag == lastToolTipTag_) {
2850 [super removeTrackingRect:tag];
2851 lastToolTipTag_ = 0;
2852 return;
2853 }
2854
2855 // If any other tracking rect is being removed, we don't know how it was
2856 // created and it's possible there's a leak involved (see Radar 3500217).
2857 NOTREACHED();
2858 }
2859
2860 // Override of (apparently) a private NSView method(!)
2861 - (void)_removeTrackingRects:(NSTrackingRectTag *)tags count:(int)count {
2862 for (int i = 0; i < count; ++i) {
2863 int tag = tags[i];
2864 if (tag == 0)
2865 continue;
2866 DCHECK(tag == kTrackingRectTag);
2867 trackingRectOwner_ = nil;
2868 }
2869 }
2870
2871 // Sends a fake NSMouseExited event to the view for its current tracking rect.
2872 - (void)_sendToolTipMouseExited {
2873 // Nothing matters except window, trackingNumber, and userData.
2874 int windowNumber = [[self window] windowNumber];
2875 NSEvent* fakeEvent = [NSEvent enterExitEventWithType:NSMouseExited
2876 location:NSZeroPoint
2877 modifierFlags:0
2878 timestamp:0
2879 windowNumber:windowNumber
2880 context:NULL
2881 eventNumber:0
2882 trackingNumber:kTrackingRectTag
2883 userData:trackingRectUserData_];
2884 [trackingRectOwner_ mouseExited:fakeEvent];
2885 }
2886
2887 // Sends a fake NSMouseEntered event to the view for its current tracking rect.
2888 - (void)_sendToolTipMouseEntered {
2889 // Nothing matters except window, trackingNumber, and userData.
2890 int windowNumber = [[self window] windowNumber];
2891 NSEvent* fakeEvent = [NSEvent enterExitEventWithType:NSMouseEntered
2892 location:NSZeroPoint
2893 modifierFlags:0
2894 timestamp:0
2895 windowNumber:windowNumber
2896 context:NULL
2897 eventNumber:0
2898 trackingNumber:kTrackingRectTag
2899 userData:trackingRectUserData_];
2900 [trackingRectOwner_ mouseEntered:fakeEvent];
2901 }
2902
2903 // Sets the view's current tooltip, to be displayed at the current mouse
2904 // location. (This does not make the tooltip appear -- as usual, it only
2905 // appears after a delay.) Pass null to remove the tooltip.
2906 - (void)setToolTipAtMousePoint:(NSString *)string {
2907 NSString *toolTip = [string length] == 0 ? nil : string;
2908 if ((toolTip && toolTip_ && [toolTip isEqualToString:toolTip_]) ||
2909 (!toolTip && !toolTip_)) {
2910 return;
2911 }
2912
2913 if (toolTip_) {
2914 [self _sendToolTipMouseExited];
2915 }
2916
2917 toolTip_.reset([toolTip copy]);
2918
2919 if (toolTip) {
2920 // See radar 3500217 for why we remove all tooltips
2921 // rather than just the single one we created.
2922 [self removeAllToolTips];
2923 NSRect wideOpenRect = NSMakeRect(-100000, -100000, 200000, 200000);
2924 lastToolTipTag_ = [self addToolTipRect:wideOpenRect
2925 owner:self
2926 userData:NULL];
2927 [self _sendToolTipMouseEntered];
2928 }
2929 }
2930
2931 // NSView calls this to get the text when displaying the tooltip.
2932 - (NSString *)view:(NSView *)view
2933 stringForToolTip:(NSToolTipTag)tag
2934 point:(NSPoint)point
2935 userData:(void *)data {
2936 return [[toolTip_ copy] autorelease];
2937 }
2938
2939 // Below is our NSTextInputClient implementation. 2752 // Below is our NSTextInputClient implementation.
2940 // 2753 //
2941 // When WebHTMLView receives a NSKeyDown event, WebHTMLView calls the following 2754 // When WebHTMLView receives a NSKeyDown event, WebHTMLView calls the following
2942 // functions to process this event. 2755 // functions to process this event.
2943 // 2756 //
2944 // [WebHTMLView keyDown] -> 2757 // [WebHTMLView keyDown] ->
2945 // EventHandler::keyEvent() -> 2758 // EventHandler::keyEvent() ->
2946 // ... 2759 // ...
2947 // [WebEditorClient handleKeyboardEvent] -> 2760 // [WebEditorClient handleKeyboardEvent] ->
2948 // [WebHTMLView _interceptEditingKeyEvent] -> 2761 // [WebHTMLView _interceptEditingKeyEvent] ->
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3494 3307
3495 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3308 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3496 // regions that are not draggable. (See ControlRegionView in 3309 // regions that are not draggable. (See ControlRegionView in
3497 // native_app_window_cocoa.mm). This requires the render host view to be 3310 // native_app_window_cocoa.mm). This requires the render host view to be
3498 // draggable by default. 3311 // draggable by default.
3499 - (BOOL)mouseDownCanMoveWindow { 3312 - (BOOL)mouseDownCanMoveWindow {
3500 return YES; 3313 return YES;
3501 } 3314 }
3502 3315
3503 @end 3316 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698