summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h
blob: 20ea39e82608d0283b56ed14a618e157581cc69e (plain)
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
// Copyright (c) 2011 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.

#import <Cocoa/Cocoa.h>

#include "base/memory/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"

// Hover state machine.  Encapsulates the hover state for
// BookmarkBarFolderController.
// A strict call order is implied with these calls.  It is ONLY valid to make
// the following state transitions:
// From:            To:               Via:
// closed           opening           scheduleOpen...:
// opening          closed            cancelPendingOpen...: or
//                  open              scheduleOpen...: completes.
// open             closing           scheduleClose...:
// closing          open              cancelPendingClose...: or
//                  closed            scheduleClose...: completes.
//
@interface BookmarkBarFolderHoverState : NSObject {
 @private
  // Enumeration of the valid states that the |hoverButton_| member can be in.
  // Because the opening and closing of hover views can be done asyncronously
  // there are periods where the hover state is in transtion between open and
  // closed.  During those times of transition the opening or closing operation
  // can be cancelled.  We serialize the opening and closing of the
  // |hoverButton_| using this state information.  This serialization is to
  // avoid race conditions where one hover button is being opened while another
  // is closing.
  enum HoverState {
    kHoverStateClosed = 0,
    kHoverStateOpening = 1,
    kHoverStateOpen = 2,
    kHoverStateClosing = 3
  };

  // Like normal menus, hovering over a folder button causes it to
  // open.  This variable is set when a hover is initiated (but has
  // not necessarily fired yet).
  scoped_nsobject<BookmarkButton> hoverButton_;

  // We model hover state as a state machine with specific allowable
  // transitions.  |hoverState_| is the state of this machine at any
  // given time.
  HoverState hoverState_;
}

// Designated initializer.
- (id)init;

// The BookmarkBarFolderHoverState decides when it is appropriate to hide
// and show the button that the BookmarkBarFolderController drags over.
- (NSDragOperation)draggingEnteredButton:(BookmarkButton*)button;

// The BookmarkBarFolderHoverState decides the fate of the hover button
// when the BookmarkBarFolderController's view is exited.
- (void)draggingExited;

@end

// Exposing these for unit testing purposes.  They are used privately in the
// implementation as well.
@interface BookmarkBarFolderHoverState(PrivateAPI)
// State change APIs.
- (void)scheduleCloseBookmarkFolderOnHoverButton;
- (void)cancelPendingCloseBookmarkFolderOnHoverButton;
- (void)scheduleOpenBookmarkFolderOnHoverButton:(BookmarkButton*)hoverButton;
- (void)cancelPendingOpenBookmarkFolderOnHoverButton;
@end

// Exposing these for unit testing purposes.  They are used only in tests.
@interface BookmarkBarFolderHoverState(TestingAPI)
// Accessors and setters for button and hover state.
- (BookmarkButton*)hoverButton;
- (HoverState)hoverState;
@end