File: browser_action_button.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (117 lines) | stat: -rw-r--r-- 3,990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2012 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.

#ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_
#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_

#import <Cocoa/Cocoa.h>

#include <memory>

#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/image_button_cell.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h"

@class BrowserActionsController;
@class MenuController;
class ToolbarActionViewController;
class ToolbarActionViewDelegateBridge;

// Fired on each drag event while the user is moving the button.
extern NSString* const kBrowserActionButtonDraggingNotification;
// Fired when the user drops the button.
extern NSString* const kBrowserActionButtonDragEndNotification;

@interface BrowserActionButton : ToolbarButton<NSMenuDelegate> {
 @private
  // Used to move the button and query whether a button is currently animating.
  base::scoped_nsobject<NSViewAnimation> moveAnimation_;

  // The controller that handles most non-view logic.
  ToolbarActionViewController* viewController_;

  // The bridge between the view controller and this object.
  std::unique_ptr<ToolbarActionViewDelegateBridge> viewControllerDelegate_;

  // The context menu controller.
  base::scoped_nsobject<MenuController> contextMenuController_;

  // A substitute context menu to use in testing. We need this because normally
  // menu code is blocking, making it difficult to test.
  NSMenu* testContextMenu_;

  // The controller for the browser actions bar that owns this button. Weak.
  BrowserActionsController* browserActionsController_;

  // Whether the button is currently being dragged.
  BOOL isBeingDragged_;

  // Drag events could be intercepted by other buttons, so to make sure that
  // this is the only button moving if it ends up being dragged. This is set to
  // YES upon |mouseDown:|.
  BOOL dragCouldStart_;

  // If a drag is not currently in progress, this is the point where the mouse
  // down event occurred, and is used to prevent a drag from starting until it
  // moves at least kMinimumDragDistance. Once a drag begins, this is the point
  // at which the drag actually started.
  NSPoint dragStartPoint_;
}

// Init the button with the frame. Does not own either |view_controller| or
// |controller|.
- (id)initWithFrame:(NSRect)frame
     viewController:(ToolbarActionViewController*)viewController
         controller:(BrowserActionsController*)controller;

- (void)setFrame:(NSRect)frameRect animate:(BOOL)animate;

- (void)updateState;

// Called when the button is removed from the toolbar and will soon be deleted.
- (void)onRemoved;

- (BOOL)isAnimating;

// Stops any currently running animation. The button's frame is unchanged.
- (void)stopAnimation;

// Returns the frame the button will occupy once animation is complete, or its
// current frame if it is not animating.
- (NSRect)frameAfterAnimation;

- (ToolbarActionViewController*)viewController;

// Returns a pointer to an autoreleased NSImage with the badge, shadow and
// cell image drawn into it.
- (NSImage*)compositedImage;

// Shows the context menu for the action.
- (void)showContextMenu;

@property(readonly, nonatomic) BOOL isBeingDragged;

@end

@interface BrowserActionButton(TestingAPI)
// Sets a context menu to use for testing purposes.
- (void)setTestContextMenu:(NSMenu*)testContextMenu;
// Returns true if the action wants to run.
- (BOOL)wantsToRunForTesting;
// Returns true if the cell is highlighted.
- (BOOL)isHighlighted;
@end

@interface BrowserActionCell : ImageButtonCell {
 @private
  // The controller for the browser actions bar that owns the button. Weak.
  BrowserActionsController* browserActionsController_;
}

@property(assign, nonatomic)
    BrowserActionsController* browserActionsController;

@end

#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_