Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/ui/views/compact_nav/compact_location_bar_view_host.cc

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GdkEvent init, NativeWidgetGtk casting, and Get[Unmodified]Character checks. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 virtual void WillProcessEvent(GdkEvent* native_event) OVERRIDE; 65 virtual void WillProcessEvent(GdkEvent* native_event) OVERRIDE;
66 virtual void DidProcessEvent(GdkEvent* native_event) OVERRIDE; 66 virtual void DidProcessEvent(GdkEvent* native_event) OVERRIDE;
67 #endif 67 #endif
68 #endif 68 #endif
69 69
70 void Observe(MessageLoopForUI* loop); 70 void Observe(MessageLoopForUI* loop);
71 void StopObserving(MessageLoopForUI* loop); 71 void StopObserving(MessageLoopForUI* loop);
72 72
73 private: 73 private:
74 // TODO(mad): would be nice to have this on the views::Event class. 74 // TODO(mad): would be nice to have this on the views::Event class.
75 #if !defined(USE_AURA)
76 #if defined(OS_WIN)
75 bool IsMouseEvent(const views::NativeEvent& native_event); 77 bool IsMouseEvent(const views::NativeEvent& native_event);
78 #elif defined(OS_LINUX)
Ben Goodger (Google) 2011/09/24 16:39:04 This should be TOOLKIT_USES_GTK, no?
msw 2011/09/26 05:08:00 Done.
79 bool IsMouseEvent(GdkEvent* gdk_event);
sadrul 2011/09/24 16:56:08 Are IsMouseEvent/IsSameTopLevelWindow not used/nec
msw 2011/09/26 05:08:00 The only caller, MouseObserver::DidProcessEvent, i
80 #endif
81 #endif
76 82
83 #if !defined(USE_AURA)
84 #if defined(OS_WIN)
77 bool IsSameTopLevelWindow(views::NativeEvent native_event); 85 bool IsSameTopLevelWindow(views::NativeEvent native_event);
86 #elif defined(OS_LINUX)
87 bool IsSameTopLevelWindow(GdkEvent* gdk_event);
88 #endif
89 #endif
78 90
79 // Tests if the event occurred on the content area, using 91 // Tests if the event occurred on the content area, using
80 // root window's coordinates. 92 // root window's coordinates.
81 bool HitContentArea(int x, int y); 93 bool HitContentArea(int x, int y);
82 94
83 // Tests if |p| in the root window's coordinate is within the |view|'s bound. 95 // 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); 96 bool HitOnScreen(const views::View* view, const gfx::Point& p);
85 97
86 CompactLocationBarViewHost* host_; 98 CompactLocationBarViewHost* host_;
87 BrowserView* browser_view_; 99 BrowserView* browser_view_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 150
139 void MouseObserver::StopObserving(MessageLoopForUI* loop) { 151 void MouseObserver::StopObserving(MessageLoopForUI* loop) {
140 #if !defined(USE_AURA) 152 #if !defined(USE_AURA)
141 if (observing_) { 153 if (observing_) {
142 loop->RemoveObserver(this); 154 loop->RemoveObserver(this);
143 observing_ = false; 155 observing_ = false;
144 } 156 }
145 #endif 157 #endif
146 } 158 }
147 159
160 #if !defined(USE_AURA)
161 #if defined(OS_WIN)
148 bool MouseObserver::IsMouseEvent(const views::NativeEvent& native_event) { 162 bool MouseObserver::IsMouseEvent(const views::NativeEvent& native_event) {
149 #if defined(OS_WIN) || defined(USE_AURA) 163 return ui::IsMouseEvent(native_event);
150 return views::IsClientMouseEvent(native_event) || 164 }
151 views::IsNonClientMouseEvent(native_event);
152 #elif defined(OS_LINUX) 165 #elif defined(OS_LINUX)
153 return native_event->type == GDK_MOTION_NOTIFY || 166 bool MouseObserver::IsMouseEvent(GdkEvent* gdk_event) {
154 native_event->type == GDK_BUTTON_PRESS || 167 return gdk_event->type == GDK_MOTION_NOTIFY ||
155 native_event->type == GDK_2BUTTON_PRESS || 168 gdk_event->type == GDK_BUTTON_PRESS ||
156 native_event->type == GDK_3BUTTON_PRESS || 169 gdk_event->type == GDK_2BUTTON_PRESS ||
157 native_event->type == GDK_BUTTON_RELEASE; 170 gdk_event->type == GDK_3BUTTON_PRESS ||
171 gdk_event->type == GDK_BUTTON_RELEASE;
172 }
158 #endif 173 #endif
159 } 174 #endif
160 175
176 #if !defined(USE_AURA)
161 // TODO(mad): Would be nice to have a NativeEvent -> NativeWindow mapping. 177 // 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 178 // Then, with a GetTopLevel receiving a NativeWindow, we could do this in a
163 // platform independent way. 179 // platform independent way.
180 #if defined(OS_WIN)
164 bool MouseObserver::IsSameTopLevelWindow(views::NativeEvent native_event) { 181 bool MouseObserver::IsSameTopLevelWindow(views::NativeEvent native_event) {
165 #if defined(USE_AURA)
166 // TODO(beng):
167 NOTIMPLEMENTED();
168 return false;
169 #elif defined(OS_WIN)
170 return platform_util::GetTopLevel(native_event.hwnd) == top_level_window_; 182 return platform_util::GetTopLevel(native_event.hwnd) == top_level_window_;
183 }
171 #elif defined(OS_LINUX) 184 #elif defined(OS_LINUX)
185 bool MouseObserver::IsSameTopLevelWindow(GdkEvent* gdk_event) {
172 return gdk_window_get_toplevel( 186 return gdk_window_get_toplevel(
173 reinterpret_cast<GdkEventAny*>(native_event)->window) == 187 reinterpret_cast<GdkEventAny*>(gdk_event)->window) ==
174 top_level_window_->window; 188 top_level_window_->window;
189 }
175 #endif 190 #endif
176 } 191 #endif
177 192
178 bool MouseObserver::HitContentArea(int x, int y) { 193 bool MouseObserver::HitContentArea(int x, int y) {
179 gfx::Point p(x, y); 194 gfx::Point p(x, y);
180 // First, exclude the location bar as it's shown on top of 195 // First, exclude the location bar as it's shown on top of
181 // content area. 196 // content area.
182 if (HitOnScreen(host_->view(), p)) { 197 if (HitOnScreen(host_->view(), p)) {
183 return false; 198 return false;
184 } 199 }
185 // Treat the bookmark as a content area when it in detached mode. We must 200 // Treat the bookmark as a content area when it in detached mode. We must
186 // check the view itself as it can be NULL for example in popup windows. 201 // check the view itself as it can be NULL for example in popup windows.
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { 559 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) {
545 return current_tab_model_index_ == index; 560 return current_tab_model_index_ == index;
546 } 561 }
547 562
548 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { 563 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) {
549 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); 564 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model();
550 return tab_strip_model->ContainsIndex(current_tab_model_index_) && 565 return tab_strip_model->ContainsIndex(current_tab_model_index_) &&
551 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> 566 tab_strip_model->GetTabContentsAt(current_tab_model_index_)->
552 tab_contents() == contents; 567 tab_contents() == contents;
553 } 568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698