Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_folder_hover_state.h
blob8d8dea73d0c65e2ab0b89d3a4f40937aa9f49ca4
1 // Copyright (c) 2011 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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
10 // Hover state machine. Encapsulates the hover state for
11 // BookmarkBarFolderController.
12 // A strict call order is implied with these calls. It is ONLY valid to make
13 // the following state transitions:
14 // From: To: Via:
15 // closed opening scheduleOpen...:
16 // opening closed cancelPendingOpen...: or
17 // open scheduleOpen...: completes.
18 // open closing scheduleClose...:
19 // closing open cancelPendingClose...: or
20 // closed scheduleClose...: completes.
22 @interface BookmarkBarFolderHoverState : NSObject {
23 @private
24 // Enumeration of the valid states that the |hoverButton_| member can be in.
25 // Because the opening and closing of hover views can be done asyncronously
26 // there are periods where the hover state is in transtion between open and
27 // closed. During those times of transition the opening or closing operation
28 // can be cancelled. We serialize the opening and closing of the
29 // |hoverButton_| using this state information. This serialization is to
30 // avoid race conditions where one hover button is being opened while another
31 // is closing.
32 enum HoverState {
33 kHoverStateClosed = 0,
34 kHoverStateOpening = 1,
35 kHoverStateOpen = 2,
36 kHoverStateClosing = 3
39 // Like normal menus, hovering over a folder button causes it to
40 // open. This variable is set when a hover is initiated (but has
41 // not necessarily fired yet).
42 base::scoped_nsobject<BookmarkButton> hoverButton_;
44 // We model hover state as a state machine with specific allowable
45 // transitions. |hoverState_| is the state of this machine at any
46 // given time.
47 HoverState hoverState_;
50 // Designated initializer.
51 - (id)init;
53 // The BookmarkBarFolderHoverState decides when it is appropriate to hide
54 // and show the button that the BookmarkBarFolderController drags over.
55 - (NSDragOperation)draggingEnteredButton:(BookmarkButton*)button;
57 // The BookmarkBarFolderHoverState decides the fate of the hover button
58 // when the BookmarkBarFolderController's view is exited.
59 - (void)draggingExited;
61 @end
63 // Exposing these for unit testing purposes. They are used privately in the
64 // implementation as well.
65 @interface BookmarkBarFolderHoverState(PrivateAPI)
66 // State change APIs.
67 - (void)scheduleCloseBookmarkFolderOnHoverButton;
68 - (void)cancelPendingCloseBookmarkFolderOnHoverButton;
69 - (void)scheduleOpenBookmarkFolderOnHoverButton:(BookmarkButton*)hoverButton;
70 - (void)cancelPendingOpenBookmarkFolderOnHoverButton;
71 @end
73 // Exposing these for unit testing purposes. They are used only in tests.
74 @interface BookmarkBarFolderHoverState(TestingAPI)
75 // Accessors and setters for button and hover state.
76 - (BookmarkButton*)hoverButton;
77 - (HoverState)hoverState;
78 @end