summaryrefslogtreecommitdiffstats
path: root/chrome/common/search_types.h
blob: 15cb8789caa4c82d789637d92a6187c4d9bc4d74 (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
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 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_COMMON_SEARCH_TYPES_H_
#define CHROME_COMMON_SEARCH_TYPES_H_

// The Mode structure encodes the visual states encountered when interacting
// with the NTP and the Omnibox.
struct SearchMode {
  // The visual state that applies to the current interaction.
  enum Type {
    // The default state means anything but the following states.
    MODE_DEFAULT,

    // On the NTP page and the NTP is ready to be displayed.
    MODE_NTP,

    // The Omnibox is modified in some way, either on the NTP or not.
    MODE_SEARCH_SUGGESTIONS,

    // On a search results page.
    MODE_SEARCH_RESULTS,
  };

  // The kind of page from which the user initiated the current search.
  enum Origin {
    // The user is searching from some random page.
    ORIGIN_DEFAULT = 0,

    // The user is searching from the NTP.
    ORIGIN_NTP,

    // The user is searching from a search results page.
    ORIGIN_SEARCH,
  };

  SearchMode() : mode(MODE_DEFAULT), origin(ORIGIN_DEFAULT) {
  }

  SearchMode(Type in_mode, Origin in_origin)
      : mode(in_mode),
        origin(in_origin) {
  }

  bool operator==(const SearchMode& rhs) const {
    return mode == rhs.mode && origin == rhs.origin;
  }

  bool operator!=(const SearchMode& rhs) const {
    return !(*this == rhs);
  }

  bool is_default() const {
    return mode == MODE_DEFAULT;
  }

  bool is_ntp() const {
    return mode == MODE_NTP;
  }

  bool is_search() const {
    return mode == MODE_SEARCH_SUGGESTIONS || mode == MODE_SEARCH_RESULTS;
  }

  bool is_search_results() const {
    return mode == MODE_SEARCH_RESULTS;
  }

  bool is_search_suggestions() const {
    return mode == MODE_SEARCH_SUGGESTIONS;
  }

  bool is_origin_default() const {
    return origin == ORIGIN_DEFAULT;
  }

  bool is_origin_search() const {
    return origin == ORIGIN_SEARCH;
  }

  bool is_origin_ntp() const {
    return origin == ORIGIN_NTP;
  }

  Type mode;
  Origin origin;
};

#endif  // CHROME_COMMON_SEARCH_TYPES_H_