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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
19 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 19 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
20 #include "chrome/browser/ui/views/compact_nav/compact_location_bar_view.h" | 20 #include "chrome/browser/ui/views/compact_nav/compact_location_bar_view.h" |
21 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
22 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" | 22 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" |
23 #include "content/browser/renderer_host/render_view_host.h" | 23 #include "content/browser/renderer_host/render_view_host.h" |
24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
25 #include "content/browser/tab_contents/tab_contents_view.h" | 25 #include "content/browser/tab_contents/tab_contents_view.h" |
26 #include "content/common/notification_source.h" | 26 #include "content/common/notification_source.h" |
27 #include "ui/base/animation/slide_animation.h" | 27 #include "ui/base/animation/slide_animation.h" |
| 28 #include "ui/base/events.h" |
28 #include "ui/base/keycodes/keyboard_codes.h" | 29 #include "ui/base/keycodes/keyboard_codes.h" |
29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
30 #include "views/controls/scrollbar/native_scroll_bar.h" | 31 #include "views/controls/scrollbar/native_scroll_bar.h" |
31 #include "views/events/event.h" | 32 #include "views/events/event.h" |
32 #include "views/focus/external_focus_tracker.h" | 33 #include "views/focus/external_focus_tracker.h" |
33 #include "views/focus/view_storage.h" | 34 #include "views/focus/view_storage.h" |
34 #include "views/widget/root_view.h" | 35 #include "views/widget/root_view.h" |
35 #include "views/widget/widget.h" | 36 #include "views/widget/widget.h" |
36 | 37 |
37 namespace { | 38 namespace { |
(...skipping 26 matching lines...) Expand all Loading... |
64 #elif defined(OS_LINUX) | 65 #elif defined(OS_LINUX) |
65 virtual void WillProcessEvent(GdkEvent* native_event) OVERRIDE; | 66 virtual void WillProcessEvent(GdkEvent* native_event) OVERRIDE; |
66 virtual void DidProcessEvent(GdkEvent* native_event) OVERRIDE; | 67 virtual void DidProcessEvent(GdkEvent* native_event) OVERRIDE; |
67 #endif | 68 #endif |
68 #endif | 69 #endif |
69 | 70 |
70 void Observe(MessageLoopForUI* loop); | 71 void Observe(MessageLoopForUI* loop); |
71 void StopObserving(MessageLoopForUI* loop); | 72 void StopObserving(MessageLoopForUI* loop); |
72 | 73 |
73 private: | 74 private: |
74 // TODO(mad): would be nice to have this on the views::Event class. | 75 bool IsSameTopLevelWindow(ui::NativeEvent native_event); |
75 bool IsMouseEvent(const views::NativeEvent& native_event); | |
76 | |
77 bool IsSameTopLevelWindow(views::NativeEvent native_event); | |
78 | 76 |
79 // Tests if the event occurred on the content area, using | 77 // Tests if the event occurred on the content area, using |
80 // root window's coordinates. | 78 // root window's coordinates. |
81 bool HitContentArea(int x, int y); | 79 bool HitContentArea(int x, int y); |
82 | 80 |
83 // Tests if |p| in the root window's coordinate is within the |view|'s bound. | 81 // Tests if |p| in the root window's coordinate is within the |view|'s bound. |
84 bool HitOnScreen(const views::View* view, const gfx::Point& p); | 82 bool HitOnScreen(const views::View* view, const gfx::Point& p); |
85 | 83 |
86 CompactLocationBarViewHost* host_; | 84 CompactLocationBarViewHost* host_; |
87 BrowserView* browser_view_; | 85 BrowserView* browser_view_; |
(...skipping 21 matching lines...) Expand all Loading... |
109 #if !defined(USE_AURA) | 107 #if !defined(USE_AURA) |
110 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
111 void MouseObserver::WillProcessMessage(const MSG& native_event) {} | 109 void MouseObserver::WillProcessMessage(const MSG& native_event) {} |
112 void MouseObserver::DidProcessMessage(const MSG& native_event) { | 110 void MouseObserver::DidProcessMessage(const MSG& native_event) { |
113 #elif defined(OS_LINUX) | 111 #elif defined(OS_LINUX) |
114 void MouseObserver::WillProcessEvent(GdkEvent* native_event) {} | 112 void MouseObserver::WillProcessEvent(GdkEvent* native_event) {} |
115 void MouseObserver::DidProcessEvent(GdkEvent* native_event) { | 113 void MouseObserver::DidProcessEvent(GdkEvent* native_event) { |
116 #endif | 114 #endif |
117 // Hide the location bar iff the mouse is pressed on the | 115 // Hide the location bar iff the mouse is pressed on the |
118 // BrowserView's content area. | 116 // BrowserView's content area. |
119 if (!IsMouseEvent(native_event)) | 117 if (!ui::IsMouseEvent(native_event)) |
120 return; | 118 return; |
121 views::MouseEvent event(native_event); | 119 views::MouseEvent event(native_event); |
122 if (event.type() == ui::ET_MOUSE_PRESSED && | 120 if (event.type() == ui::ET_MOUSE_PRESSED && |
123 IsSameTopLevelWindow(native_event) && | 121 IsSameTopLevelWindow(native_event) && |
124 HitContentArea(event.x(), event.y())) { | 122 HitContentArea(event.x(), event.y())) { |
125 host_->Hide(true); | 123 host_->Hide(true); |
126 } | 124 } |
127 } | 125 } |
128 #endif | 126 #endif |
129 | 127 |
130 void MouseObserver::Observe(MessageLoopForUI* loop) { | 128 void MouseObserver::Observe(MessageLoopForUI* loop) { |
131 #if !defined(USE_AURA) | 129 #if !defined(USE_AURA) |
132 if (!observing_) { | 130 if (!observing_) { |
133 loop->AddObserver(this); | 131 loop->AddObserver(this); |
134 observing_ = true; | 132 observing_ = true; |
135 } | 133 } |
136 #endif | 134 #endif |
137 } | 135 } |
138 | 136 |
139 void MouseObserver::StopObserving(MessageLoopForUI* loop) { | 137 void MouseObserver::StopObserving(MessageLoopForUI* loop) { |
140 #if !defined(USE_AURA) | 138 #if !defined(USE_AURA) |
141 if (observing_) { | 139 if (observing_) { |
142 loop->RemoveObserver(this); | 140 loop->RemoveObserver(this); |
143 observing_ = false; | 141 observing_ = false; |
144 } | 142 } |
145 #endif | 143 #endif |
146 } | 144 } |
147 | 145 |
148 bool MouseObserver::IsMouseEvent(const views::NativeEvent& native_event) { | |
149 #if defined(OS_WIN) || defined(USE_AURA) | |
150 return views::IsClientMouseEvent(native_event) || | |
151 views::IsNonClientMouseEvent(native_event); | |
152 #elif defined(OS_LINUX) | |
153 return native_event->type == GDK_MOTION_NOTIFY || | |
154 native_event->type == GDK_BUTTON_PRESS || | |
155 native_event->type == GDK_2BUTTON_PRESS || | |
156 native_event->type == GDK_3BUTTON_PRESS || | |
157 native_event->type == GDK_BUTTON_RELEASE; | |
158 #endif | |
159 } | |
160 | |
161 // TODO(mad): Would be nice to have a NativeEvent -> NativeWindow mapping. | 146 // TODO(mad): Would be nice to have a NativeEvent -> NativeWindow mapping. |
162 // Then, with a GetTopLevel receiving a NativeWindow, we could do this in a | 147 // Then, with a GetTopLevel receiving a NativeWindow, we could do this in a |
163 // platform independent way. | 148 // platform independent way. |
164 bool MouseObserver::IsSameTopLevelWindow(views::NativeEvent native_event) { | 149 bool MouseObserver::IsSameTopLevelWindow(ui::NativeEvent native_event) { |
165 #if defined(USE_AURA) | 150 #if defined(USE_AURA) |
166 // TODO(beng): | 151 // TODO(beng): |
167 NOTIMPLEMENTED(); | 152 NOTIMPLEMENTED(); |
168 return false; | 153 return false; |
169 #elif defined(OS_WIN) | 154 #elif defined(OS_WIN) |
170 return platform_util::GetTopLevel(native_event.hwnd) == top_level_window_; | 155 return platform_util::GetTopLevel(native_event.hwnd) == top_level_window_; |
171 #elif defined(OS_LINUX) | 156 #elif defined(OS_LINUX) |
172 return gdk_window_get_toplevel( | 157 return gdk_window_get_toplevel( |
173 reinterpret_cast<GdkEventAny*>(native_event)->window) == | 158 reinterpret_cast<GdkEventAny*>(native_event)->window) == |
174 top_level_window_->window; | 159 top_level_window_->window; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { | 529 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { |
545 return current_tab_model_index_ == index; | 530 return current_tab_model_index_ == index; |
546 } | 531 } |
547 | 532 |
548 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { | 533 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { |
549 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); | 534 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); |
550 return tab_strip_model->ContainsIndex(current_tab_model_index_) && | 535 return tab_strip_model->ContainsIndex(current_tab_model_index_) && |
551 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> | 536 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> |
552 tab_contents() == contents; | 537 tab_contents() == contents; |
553 } | 538 } |
OLD | NEW |