Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: chrome/browser/ui/search/search_model.cc

Issue 10644002: Add core plumbing for Instant Extended work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Header Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "chrome/browser/ui/search/search_model.h"
6
7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/ui/search/search.h"
9 #include "chrome/browser/ui/search/search_model_observer.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_contents.h"
13
14 namespace chrome {
15 namespace search {
16
17 const SkColor kNTPBackgroundColor = SkColorSetRGB(0xF5, 0xF5, 0xF5);
18 const SkColor kResultsSeparatorColor = SkColorSetRGB(226, 226, 226);
19 const SkColor kSearchBackgroundColor = SK_ColorWHITE;
20
21 const int kOmniboxYPosition = 310;
22 const int kSearchResultsHeight = 122;
23
24 SearchModel::SearchModel(TabContents* contents)
25 : contents_(contents) {
26 }
27
28 SearchModel::~SearchModel() {
29 }
30
31 void SearchModel::SetMode(const Mode& mode) {
32 if (contents_ == NULL)
33 return;
34
35 DCHECK(IsInstantExtendedAPIEnabled(contents_->profile()))
36 << "Please do not try to set the SearchModel mode without first "
37 << "checking if Search is enabled.";
38
39 if (mode_ == mode)
40 return;
41
42 mode_ = mode;
43
44 FOR_EACH_OBSERVER(SearchModelObserver, observers_, ModeChanged(mode_));
45
46 // Animation is transient, it is cleared after observers are notified.
47 mode_.animate = false;
48 }
49
50 void SearchModel::MaybeChangeMode(Mode::Type from_mode, Mode::Type to_mode) {
51 if (mode_.mode == from_mode) {
52 Mode mode(to_mode, true);
53 SetMode(mode);
54 }
55 }
56
57 void SearchModel::AddObserver(SearchModelObserver* observer) {
58 observers_.AddObserver(observer);
59 }
60
61 void SearchModel::RemoveObserver(SearchModelObserver* observer) {
62 observers_.RemoveObserver(observer);
63 }
64
65 gfx::Rect GetNTPOmniboxBounds(const gfx::Size& web_contents_size) {
66 const double kNTPPageWidthRatio = 0.73f;
67 if (web_contents_size.IsEmpty())
68 return gfx::Rect();
69 int width = static_cast<int>(kNTPPageWidthRatio *
70 static_cast<double>(web_contents_size.width()));
71 int x = (web_contents_size.width() - width) / 2;
72 return gfx::Rect(x, kOmniboxYPosition, width, 0);
73 }
74
75 } // namespace search
76 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698