| Index: chrome/browser/ui/search/search_model.cc
|
| diff --git a/chrome/browser/ui/search/search_model.cc b/chrome/browser/ui/search/search_model.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9fa0565f0f460db76d6394cbac82d66a0e480587
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/search/search_model.cc
|
| @@ -0,0 +1,76 @@
|
| +// 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.
|
| +
|
| +#include "chrome/browser/ui/search/search_model.h"
|
| +
|
| +#include "chrome/browser/google/google_util.h"
|
| +#include "chrome/browser/ui/search/search.h"
|
| +#include "chrome/browser/ui/search/search_model_observer.h"
|
| +#include "chrome/browser/ui/tab_contents/tab_contents.h"
|
| +#include "chrome/common/url_constants.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +namespace chrome {
|
| +namespace search {
|
| +
|
| +const SkColor kNTPBackgroundColor = SkColorSetRGB(0xF5, 0xF5, 0xF5);
|
| +const SkColor kResultsSeparatorColor = SkColorSetRGB(226, 226, 226);
|
| +const SkColor kSearchBackgroundColor = SK_ColorWHITE;
|
| +
|
| +const int kOmniboxYPosition = 310;
|
| +const int kSearchResultsHeight = 122;
|
| +
|
| +SearchModel::SearchModel(TabContents* contents)
|
| + : contents_(contents) {
|
| +}
|
| +
|
| +SearchModel::~SearchModel() {
|
| +}
|
| +
|
| +void SearchModel::SetMode(const Mode& mode) {
|
| + if (contents_ == NULL)
|
| + return;
|
| +
|
| + DCHECK(IsInstantExtendedAPIEnabled(contents_->profile()))
|
| + << "Please do not try to set the SearchModel mode without first "
|
| + << "checking if Search is enabled.";
|
| +
|
| + if (mode_ == mode)
|
| + return;
|
| +
|
| + mode_ = mode;
|
| +
|
| + FOR_EACH_OBSERVER(SearchModelObserver, observers_, ModeChanged(mode_));
|
| +
|
| + // Animation is transient, it is cleared after observers are notified.
|
| + mode_.animate = false;
|
| +}
|
| +
|
| +void SearchModel::MaybeChangeMode(Mode::Type from_mode, Mode::Type to_mode) {
|
| + if (mode_.mode == from_mode) {
|
| + Mode mode(to_mode, true);
|
| + SetMode(mode);
|
| + }
|
| +}
|
| +
|
| +void SearchModel::AddObserver(SearchModelObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void SearchModel::RemoveObserver(SearchModelObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +gfx::Rect GetNTPOmniboxBounds(const gfx::Size& web_contents_size) {
|
| + const double kNTPPageWidthRatio = 0.73f;
|
| + if (web_contents_size.IsEmpty())
|
| + return gfx::Rect();
|
| + int width = static_cast<int>(kNTPPageWidthRatio *
|
| + static_cast<double>(web_contents_size.width()));
|
| + int x = (web_contents_size.width() - width) / 2;
|
| + return gfx::Rect(x, kOmniboxYPosition, width, 0);
|
| +}
|
| +
|
| +} // namespace search
|
| +} // namespace chrome
|
|
|