summaryrefslogtreecommitdiffstats
path: root/components/view_manager/focus_controller.h
blob: 74599c53165d5ed866190cdefe48260ce9e72a90 (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
// Copyright 2015 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 COMPONENTS_VIEW_MANAGER_FOCUS_CONTROLLER_H_
#define COMPONENTS_VIEW_MANAGER_FOCUS_CONTROLLER_H_

#include "base/memory/scoped_ptr.h"
#include "components/view_manager/server_view_drawn_tracker_observer.h"

namespace view_manager {

class FocusControllerDelegate;
class ServerView;
class ServerViewDrawnTracker;

// Tracks a focused view. Focus is moved to another view when the drawn state
// of the focused view changes and the delegate is notified.
class FocusController : public ServerViewDrawnTrackerObserver {
 public:
  explicit FocusController(FocusControllerDelegate* delegate);
  ~FocusController() override;

  // Sets the focused view. Does nothing if |view| is currently focused. This
  // does not notify the delegate.
  void SetFocusedView(ServerView* view);
  ServerView* GetFocusedView();

 private:
  // Describes the source of the change.
  enum ChangeSource {
    CHANGE_SOURCE_EXPLICIT,
    CHANGE_SOURCE_DRAWN_STATE_CHANGED,
  };

  // Implementation of SetFocusedView().
  void SetFocusedViewImpl(ServerView* view, ChangeSource change_source);

  // ServerViewDrawnTrackerObserver:
  void OnDrawnStateChanged(ServerView* ancestor,
                           ServerView* view,
                           bool is_drawn) override;

  FocusControllerDelegate* delegate_;
  scoped_ptr<ServerViewDrawnTracker> drawn_tracker_;

  DISALLOW_COPY_AND_ASSIGN(FocusController);
};

}  // namespace view_manager

#endif  // COMPONENTS_VIEW_MANAGER_FOCUS_CONTROLLER_H_