OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/instant/instant_overlay_model.h" |
| 6 |
| 7 #include "chrome/browser/instant/instant_controller.h" |
| 8 #include "chrome/browser/instant/instant_overlay_model_observer.h" |
| 9 |
| 10 InstantOverlayModel::InstantOverlayModel(InstantController* controller) |
| 11 : height_(0), |
| 12 height_units_(INSTANT_SIZE_PIXELS), |
| 13 overlay_contents_(NULL), |
| 14 controller_(controller) { |
| 15 } |
| 16 |
| 17 InstantOverlayModel::~InstantOverlayModel() { |
| 18 } |
| 19 |
| 20 void InstantOverlayModel::SetOverlayState(const chrome::search::Mode& mode, |
| 21 int height, |
| 22 InstantSizeUnits height_units) { |
| 23 if (mode_.mode == mode.mode && height_ == height && |
| 24 height_units_ == height_units) { |
| 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 mode() doesn't return something unexpected). |
| 28 mode_ = mode; |
| 29 return; |
| 30 } |
| 31 |
| 32 DVLOG(1) << "SetOverlayState: " << mode_.mode << " to " << mode.mode; |
| 33 mode_ = mode; |
| 34 height_ = height; |
| 35 height_units_ = height_units; |
| 36 |
| 37 FOR_EACH_OBSERVER(InstantOverlayModelObserver, observers_, |
| 38 OverlayStateChanged(*this)); |
| 39 } |
| 40 |
| 41 void InstantOverlayModel::SetOverlayContents( |
| 42 content::WebContents* overlay_contents) { |
| 43 if (overlay_contents_ == overlay_contents) |
| 44 return; |
| 45 |
| 46 overlay_contents_ = overlay_contents; |
| 47 |
| 48 FOR_EACH_OBSERVER(InstantOverlayModelObserver, observers_, |
| 49 OverlayStateChanged(*this)); |
| 50 } |
| 51 |
| 52 content::WebContents* InstantOverlayModel::GetOverlayContents() const { |
| 53 // |controller_| maybe NULL durning tests. |
| 54 if (controller_) |
| 55 return controller_->GetOverlayContents(); |
| 56 return overlay_contents_; |
| 57 } |
| 58 |
| 59 void InstantOverlayModel::AddObserver(InstantOverlayModelObserver* observer) { |
| 60 observers_.AddObserver(observer); |
| 61 } |
| 62 |
| 63 void InstantOverlayModel::RemoveObserver( |
| 64 InstantOverlayModelObserver* observer) { |
| 65 observers_.RemoveObserver(observer); |
| 66 } |
OLD | NEW |