Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / components / bubble / bubble_controller.h
blob756ab34bfc3d70ec8d9272c24cfdda11d507ff65
1 // Copyright 2015 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 #ifndef COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_
6 #define COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/thread_checker.h"
11 #include "components/bubble/bubble_close_reason.h"
13 class BubbleDelegate;
14 class BubbleManager;
15 class BubbleUi;
17 // BubbleController is responsible for the lifetime of the delegate and its UI.
18 class BubbleController : public base::SupportsWeakPtr<BubbleController> {
19 public:
20 explicit BubbleController(BubbleManager* manager,
21 scoped_ptr<BubbleDelegate> delegate);
22 virtual ~BubbleController();
24 // Calls CloseBubble on the associated BubbleManager.
25 bool CloseBubble(BubbleCloseReason reason);
27 // Calls UpdateBubbleUi on the associated BubbleManager.
28 // Returns true if the UI was updated.
29 bool UpdateBubbleUi();
31 private:
32 friend class BubbleManager;
34 // Creates and shows the UI for the delegate.
35 void Show();
37 // Notifies the bubble UI that it should update its anchor location.
38 // Important when there's a UI change (ex: fullscreen transition).
39 void UpdateAnchorPosition();
41 // Cleans up the delegate and its UI if it closed.
42 // Returns true if the bubble was closed.
43 bool ShouldClose(BubbleCloseReason reason);
45 BubbleManager* manager_;
46 scoped_ptr<BubbleDelegate> delegate_;
47 scoped_ptr<BubbleUi> bubble_ui_;
49 // Verify that functions that affect the UI are done on the same thread.
50 base::ThreadChecker thread_checker_;
52 DISALLOW_COPY_AND_ASSIGN(BubbleController);
55 #endif // COMPONENTS_BUBBLE_BUBBLE_CONTROLLER_H_