summaryrefslogtreecommitdiffstats
path: root/chrome/browser/instant/instant_model.h
blob: aacedd2f3ca5a4adeb89c86cb4301fa2f487dd70 (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
// Copyright 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_INSTANT_INSTANT_MODEL_H_
#define CHROME_BROWSER_INSTANT_INSTANT_MODEL_H_

#include "base/basictypes.h"
#include "base/observer_list.h"
#include "chrome/common/instant_types.h"
#include "chrome/common/search_types.h"

class InstantController;
class InstantModelObserver;
class TabContents;

// Holds state that is important to any views concerned with visibility and
// layout of the Instant preview.
class InstantModel {
 public:
  explicit InstantModel(InstantController* controller);
  ~InstantModel();

  // InstantModel only uses Mode::mode internally. Other parts of Mode, such as
  // Mode::origin, may have arbitrary values, and should be ignored.
  const chrome::search::Mode& mode() const { return mode_; }
  int height() const { return height_; }
  InstantSizeUnits height_units() const { return height_units_; }

  void SetPreviewState(const chrome::search::Mode& mode,
                       int height,
                       InstantSizeUnits height_units);

  void SetPreviewContents(TabContents* preview_contents);
  TabContents* GetPreviewContents() const;

  // Add and remove observers.
  void AddObserver(InstantModelObserver* observer) const;
  void RemoveObserver(InstantModelObserver* observer) const;

 private:
  chrome::search::Mode mode_;
  int height_;
  InstantSizeUnits height_units_;

  // Weak. Remembers the last set preview contents to detect changes. Actual
  // preview contents is fetched from the |controller_| as this may not always
  // reflect the actual preview in effect.
  TabContents* preview_contents_;

  // Weak. The controller currently holds some model state.
  // TODO(dhollowa): Remove this, transfer all model state to InstantModel.
  InstantController* const controller_;

  // Observers.
  mutable ObserverList<InstantModelObserver> observers_;

  DISALLOW_COPY_AND_ASSIGN(InstantModel);
};

#endif  // CHROME_BROWSER_INSTANT_INSTANT_MODEL_H_