OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/instant/instant_model.h" | 5 #include "chrome/browser/instant/instant_model.h" |
6 | 6 |
7 #include "chrome/browser/instant/instant_controller.h" | 7 #include "base/stringprintf.h" |
8 #include "chrome/browser/instant/instant_model_observer.h" | 8 #include "chrome/browser/instant/instant_model_observer.h" |
| 9 #include "chrome/browser/instant/instant_service.h" |
9 | 10 |
10 InstantModel::InstantModel(InstantController* controller) | 11 InstantModel::InstantModel(InstantService* service) |
11 : height_(0), | 12 : overlay_(NULL), |
12 height_units_(INSTANT_SIZE_PIXELS), | 13 height_(0), |
13 preview_contents_(NULL), | 14 is_height_in_pixels_(false), |
14 controller_(controller) { | 15 service_(service) { |
15 } | 16 } |
16 | 17 |
17 InstantModel::~InstantModel() { | 18 InstantModel::~InstantModel() { |
18 } | 19 } |
19 | 20 |
20 void InstantModel::SetPreviewState(const chrome::search::Mode& mode, | 21 void InstantModel::SetOverlayState(content::WebContents* overlay, |
21 int height, | 22 int height, |
22 InstantSizeUnits height_units) { | 23 bool is_height_in_pixels) { |
23 if (mode_.mode == mode.mode && height_ == height && | 24 if (overlay_ == overlay && height_ == height && |
24 height_units_ == height_units) { | 25 is_height_in_pixels_ == is_height_in_pixels) |
25 // Mode::mode hasn't changed, but perhaps bits that we ignore (such as | |
26 // Mode::origin) have. Update |mode_| anyway, so it's consistent with the | |
27 // argument (so InstantModel::mode() doesn't return something unexpected). | |
28 mode_ = mode; | |
29 return; | 26 return; |
30 } | |
31 | 27 |
32 DVLOG(1) << "SetPreviewState: " << mode_.mode << " to " << mode.mode; | 28 service_->LogDebugEvent(base::StringPrintf("%p SetOverlayState %s", |
33 mode_ = mode; | 29 this, |
| 30 overlay ? "showed" : "hidden")); |
| 31 overlay_ = overlay; |
34 height_ = height; | 32 height_ = height; |
35 height_units_ = height_units; | 33 is_height_in_pixels_ = is_height_in_pixels; |
36 | 34 |
37 FOR_EACH_OBSERVER(InstantModelObserver, observers_, | 35 FOR_EACH_OBSERVER(InstantModelObserver, observers_, |
38 PreviewStateChanged(*this)); | 36 OverlayStateChanged(*this)); |
39 } | |
40 | |
41 void InstantModel::SetPreviewContents(content::WebContents* preview_contents) { | |
42 if (preview_contents_ == preview_contents) | |
43 return; | |
44 | |
45 preview_contents_ = preview_contents; | |
46 | |
47 FOR_EACH_OBSERVER(InstantModelObserver, observers_, | |
48 PreviewStateChanged(*this)); | |
49 } | |
50 | |
51 content::WebContents* InstantModel::GetPreviewContents() const { | |
52 // |controller_| maybe NULL durning tests. | |
53 if (controller_) | |
54 return controller_->GetPreviewContents(); | |
55 return preview_contents_; | |
56 } | 37 } |
57 | 38 |
58 void InstantModel::AddObserver(InstantModelObserver* observer) { | 39 void InstantModel::AddObserver(InstantModelObserver* observer) { |
59 observers_.AddObserver(observer); | 40 observers_.AddObserver(observer); |
60 } | 41 } |
61 | 42 |
62 void InstantModel::RemoveObserver(InstantModelObserver* observer) { | 43 void InstantModel::RemoveObserver(InstantModelObserver* observer) { |
63 observers_.RemoveObserver(observer); | 44 observers_.RemoveObserver(observer); |
64 } | 45 } |
OLD | NEW |