| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/views/compact_nav/compact_location_bar_view_host.h" | 5 #include "chrome/browser/ui/views/compact_nav/compact_location_bar_view_host.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // TODO(stevet): Share this with CompactLocationBarView. This is the actual | 40 // TODO(stevet): Share this with CompactLocationBarView. This is the actual |
| 41 // height, without the overlap added. | 41 // height, without the overlap added. |
| 42 const int kCompactNavbarSpacerHeight = 4; | 42 const int kCompactNavbarSpacerHeight = 4; |
| 43 const int kBookmarkBarLocationBarOverlap = 2; | 43 const int kBookmarkBarLocationBarOverlap = 2; |
| 44 const int kSpacerLocationbarOverlap = 1; | 44 const int kSpacerLocationbarOverlap = 1; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 // An mouse event observer to detect a mouse click on | 48 // An mouse event observer to detect a mouse click on |
| 49 // BrowserView's content area and hide the location bar. | 49 // BrowserView's content area and hide the location bar. |
| 50 class MouseObserver | 50 class MouseObserver : public MessageLoopForUI::Observer { |
| 51 #if !defined(USE_AURA) | |
| 52 : public MessageLoopForUI::Observer | |
| 53 #endif | |
| 54 { | |
| 55 public: | 51 public: |
| 56 MouseObserver(CompactLocationBarViewHost* host, BrowserView* view); | 52 MouseObserver(CompactLocationBarViewHost* host, BrowserView* view); |
| 57 ~MouseObserver(); | 53 ~MouseObserver(); |
| 58 | 54 |
| 59 // MessageLoopForUI::Observer overrides. | 55 // MessageLoopForUI::Observer overrides. |
| 60 #if !defined(USE_AURA) | 56 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) |
| 61 #if defined(OS_WIN) | 57 virtual base::EventStatus WillProcessEvent(const base::NativeEvent& event) OVE
RRIDE; |
| 62 virtual void WillProcessMessage(const MSG& native_event) OVERRIDE; | 58 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; |
| 63 virtual void DidProcessMessage(const MSG& native_event) OVERRIDE; | 59 #elif defined(TOOLKIT_USES_GTK) |
| 64 #elif defined(OS_LINUX) | 60 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; |
| 65 virtual void WillProcessEvent(GdkEvent* native_event) OVERRIDE; | 61 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; |
| 66 virtual void DidProcessEvent(GdkEvent* native_event) OVERRIDE; | |
| 67 #endif | |
| 68 #endif | 62 #endif |
| 69 | 63 |
| 70 void Observe(MessageLoopForUI* loop); | 64 void Observe(MessageLoopForUI* loop); |
| 71 void StopObserving(MessageLoopForUI* loop); | 65 void StopObserving(MessageLoopForUI* loop); |
| 72 | 66 |
| 73 private: | 67 private: |
| 74 // TODO(mad): would be nice to have this on the views::Event class. | 68 // TODO(mad): would be nice to have this on the views::Event class. |
| 75 bool IsMouseEvent(const views::NativeEvent& native_event); | 69 bool IsMouseEvent(const views::NativeEvent& native_event); |
| 76 | 70 |
| 77 bool IsSameTopLevelWindow(views::NativeEvent native_event); | 71 bool IsSameTopLevelWindow(views::NativeEvent native_event); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 DCHECK(host_); | 93 DCHECK(host_); |
| 100 DCHECK(browser_view_); | 94 DCHECK(browser_view_); |
| 101 DCHECK(browser_view_->GetWidget()); | 95 DCHECK(browser_view_->GetWidget()); |
| 102 top_level_window_ = browser_view_->GetWidget()->GetNativeView(); | 96 top_level_window_ = browser_view_->GetWidget()->GetNativeView(); |
| 103 } | 97 } |
| 104 | 98 |
| 105 MouseObserver::~MouseObserver() { | 99 MouseObserver::~MouseObserver() { |
| 106 StopObserving(MessageLoopForUI::current()); | 100 StopObserving(MessageLoopForUI::current()); |
| 107 } | 101 } |
| 108 | 102 |
| 109 #if !defined(USE_AURA) | 103 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) |
| 104 base::EventStatus MouseObserver::WillProcessEvent(const base::NativeEvent& nativ
e_event) { |
| 105 return base::EVENT_CONTINUE; |
| 106 } |
| 107 #elif defined(TOOLKIT_USES_GTK) |
| 108 void MouseObserver::WillProcessEvent(GdkEvent* native_event) {} |
| 109 #endif |
| 110 |
| 111 #if defined(TOUCH_UI) || defined(USE_AURA) |
| 112 void MouseObserver::DidProcessEvent(const base::NativeEvent& native_event) { |
| 113 NOTIMPLEMENTED(); |
| 114 } |
| 115 |
| 116 #else |
| 117 |
| 110 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 111 void MouseObserver::WillProcessMessage(const MSG& native_event) {} | 119 void MouseObserver::DidProcessEvent(const base::NativeEvent& native_event) { |
| 112 void MouseObserver::DidProcessMessage(const MSG& native_event) { | 120 #elif defined(TOOLKIT_USES_GTK) |
| 113 #elif defined(OS_LINUX) | |
| 114 void MouseObserver::WillProcessEvent(GdkEvent* native_event) {} | |
| 115 void MouseObserver::DidProcessEvent(GdkEvent* native_event) { | 121 void MouseObserver::DidProcessEvent(GdkEvent* native_event) { |
| 116 #endif | 122 #endif |
| 117 // Hide the location bar iff the mouse is pressed on the | 123 // Hide the location bar iff the mouse is pressed on the |
| 118 // BrowserView's content area. | 124 // BrowserView's content area. |
| 119 if (!IsMouseEvent(native_event)) | 125 if (!IsMouseEvent(native_event)) |
| 120 return; | 126 return; |
| 121 views::MouseEvent event(native_event); | 127 views::MouseEvent event(native_event); |
| 122 if (event.type() == ui::ET_MOUSE_PRESSED && | 128 if (event.type() == ui::ET_MOUSE_PRESSED && |
| 123 IsSameTopLevelWindow(native_event) && | 129 IsSameTopLevelWindow(native_event) && |
| 124 HitContentArea(event.x(), event.y())) { | 130 HitContentArea(event.x(), event.y())) { |
| 125 host_->Hide(true); | 131 host_->Hide(true); |
| 126 } | 132 } |
| 127 } | 133 } |
| 128 #endif | 134 |
| 135 #endif // defined(TOUCH_UI) || defiend(USE_AURA) |
| 129 | 136 |
| 130 void MouseObserver::Observe(MessageLoopForUI* loop) { | 137 void MouseObserver::Observe(MessageLoopForUI* loop) { |
| 131 #if !defined(USE_AURA) | 138 #if !defined(USE_AURA) |
| 132 if (!observing_) { | 139 if (!observing_) { |
| 133 loop->AddObserver(this); | 140 loop->AddObserver(this); |
| 134 observing_ = true; | 141 observing_ = true; |
| 135 } | 142 } |
| 136 #endif | 143 #endif |
| 137 } | 144 } |
| 138 | 145 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { | 551 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { |
| 545 return current_tab_model_index_ == index; | 552 return current_tab_model_index_ == index; |
| 546 } | 553 } |
| 547 | 554 |
| 548 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { | 555 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { |
| 549 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); | 556 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); |
| 550 return tab_strip_model->ContainsIndex(current_tab_model_index_) && | 557 return tab_strip_model->ContainsIndex(current_tab_model_index_) && |
| 551 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> | 558 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> |
| 552 tab_contents() == contents; | 559 tab_contents() == contents; |
| 553 } | 560 } |
| OLD | NEW |