| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/tabs/tab.h" | 5 #include "chrome/browser/views/tabs/tab.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gfx/size.h" | 13 #include "base/gfx/size.h" |
| 14 #include "chrome/browser/views/frame/browser_extender.h" |
| 15 #include "chrome/browser/views/frame/browser_view.h" |
| 16 #include "chrome/browser/views/tabs/tab_strip.h" |
| 14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 15 #include "views/controls/menu/simple_menu_model.h" | 18 #include "views/controls/menu/simple_menu_model.h" |
| 16 #include "views/widget/tooltip_manager.h" | 19 #include "views/widget/tooltip_manager.h" |
| 17 #include "views/widget/widget.h" | 20 #include "views/widget/widget.h" |
| 18 | 21 |
| 19 const std::string Tab::kTabClassName = "browser/tabs/Tab"; | 22 const std::string Tab::kTabClassName = "browser/tabs/Tab"; |
| 20 | 23 |
| 21 static const SkScalar kTabCapWidth = 15; | 24 static const SkScalar kTabCapWidth = 15; |
| 22 static const SkScalar kTabTopCurveWidth = 4; | 25 static const SkScalar kTabTopCurveWidth = 4; |
| 23 static const SkScalar kTabBottomCurveWidth = 3; | 26 static const SkScalar kTabBottomCurveWidth = 3; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 void Tab::GetHitTestMask(gfx::Path* mask) const { | 151 void Tab::GetHitTestMask(gfx::Path* mask) const { |
| 149 MakePathForTab(mask); | 152 MakePathForTab(mask); |
| 150 } | 153 } |
| 151 | 154 |
| 152 bool Tab::OnMousePressed(const views::MouseEvent& event) { | 155 bool Tab::OnMousePressed(const views::MouseEvent& event) { |
| 153 if (event.IsOnlyLeftMouseButton()) { | 156 if (event.IsOnlyLeftMouseButton()) { |
| 154 // Store whether or not we were selected just now... we only want to be | 157 // Store whether or not we were selected just now... we only want to be |
| 155 // able to drag foreground tabs, so we don't start dragging the tab if | 158 // able to drag foreground tabs, so we don't start dragging the tab if |
| 156 // it was in the background. | 159 // it was in the background. |
| 157 bool just_selected = !IsSelected(); | 160 bool just_selected = !IsSelected(); |
| 158 if (just_selected) | 161 if (just_selected) { |
| 159 delegate_->SelectTab(this); | 162 delegate_->SelectTab(this); |
| 163 // This is a hack to update the compact location bar when the tab |
| 164 // is selected. This is just an experiement and will be modified later. |
| 165 // TODO(oshima): Improve the BrowserExtender interface if we |
| 166 // decided to keep this UI, or remove this otherwise. |
| 167 GetBrowserExtender()->OnMouseEnteredToTab(this); |
| 168 } |
| 160 delegate_->MaybeStartDrag(this, event); | 169 delegate_->MaybeStartDrag(this, event); |
| 161 } | 170 } |
| 162 return true; | 171 return true; |
| 163 } | 172 } |
| 164 | 173 |
| 165 bool Tab::OnMouseDragged(const views::MouseEvent& event) { | 174 bool Tab::OnMouseDragged(const views::MouseEvent& event) { |
| 166 delegate_->ContinueDrag(event); | 175 delegate_->ContinueDrag(event); |
| 167 return true; | 176 return true; |
| 168 } | 177 } |
| 169 | 178 |
| 170 void Tab::OnMouseReleased(const views::MouseEvent& event, bool canceled) { | 179 void Tab::OnMouseReleased(const views::MouseEvent& event, bool canceled) { |
| 171 // Notify the drag helper that we're done with any potential drag operations. | 180 // Notify the drag helper that we're done with any potential drag operations. |
| 172 // Clean up the drag helper, which is re-created on the next mouse press. | 181 // Clean up the drag helper, which is re-created on the next mouse press. |
| 173 // In some cases, ending the drag will schedule the tab for destruction; if | 182 // In some cases, ending the drag will schedule the tab for destruction; if |
| 174 // so, bail immediately, since our members are already dead and we shouldn't | 183 // so, bail immediately, since our members are already dead and we shouldn't |
| 175 // do anything else except drop the tab where it is. | 184 // do anything else except drop the tab where it is. |
| 176 if (delegate_->EndDrag(canceled)) | 185 if (delegate_->EndDrag(canceled)) |
| 177 return; | 186 return; |
| 178 | 187 |
| 179 // Close tab on middle click, but only if the button is released over the tab | 188 // Close tab on middle click, but only if the button is released over the tab |
| 180 // (normal windows behavior is to discard presses of a UI element where the | 189 // (normal windows behavior is to discard presses of a UI element where the |
| 181 // releases happen off the element). | 190 // releases happen off the element). |
| 182 if (event.IsMiddleMouseButton() && HitTest(event.location())) | 191 if (event.IsMiddleMouseButton() && HitTest(event.location())) |
| 183 delegate_->CloseTab(this); | 192 delegate_->CloseTab(this); |
| 184 } | 193 } |
| 185 | 194 |
| 195 void Tab::OnMouseEntered(const views::MouseEvent& event) { |
| 196 GetBrowserExtender()->OnMouseEnteredToTab(this); |
| 197 } |
| 198 |
| 199 void Tab::OnMouseMoved(const views::MouseEvent& event) { |
| 200 GetBrowserExtender()->OnMouseMovedOnTab(this); |
| 201 } |
| 202 |
| 203 void Tab::OnMouseExited(const views::MouseEvent& event) { |
| 204 GetBrowserExtender()->OnMouseExitedFromTab(this); |
| 205 } |
| 206 |
| 186 bool Tab::GetTooltipText(int x, int y, std::wstring* tooltip) { | 207 bool Tab::GetTooltipText(int x, int y, std::wstring* tooltip) { |
| 187 std::wstring title = GetTitle(); | 208 std::wstring title = GetTitle(); |
| 188 if (!title.empty()) { | 209 if (!title.empty()) { |
| 189 // Only show the tooltip if the title is truncated. | 210 // Only show the tooltip if the title is truncated. |
| 190 gfx::Font font; | 211 gfx::Font font; |
| 191 if (font.GetStringWidth(title) > title_bounds().width()) { | 212 if (font.GetStringWidth(title) > title_bounds().width()) { |
| 192 *tooltip = title; | 213 *tooltip = title; |
| 193 return true; | 214 return true; |
| 194 } | 215 } |
| 195 } | 216 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // views::ButtonListener implementation: | 250 // views::ButtonListener implementation: |
| 230 | 251 |
| 231 void Tab::ButtonPressed(views::Button* sender, const views::Event& event) { | 252 void Tab::ButtonPressed(views::Button* sender, const views::Event& event) { |
| 232 if (sender == close_button()) | 253 if (sender == close_button()) |
| 233 delegate_->CloseTab(this); | 254 delegate_->CloseTab(this); |
| 234 } | 255 } |
| 235 | 256 |
| 236 /////////////////////////////////////////////////////////////////////////////// | 257 /////////////////////////////////////////////////////////////////////////////// |
| 237 // Tab, private: | 258 // Tab, private: |
| 238 | 259 |
| 260 BrowserExtender* Tab::GetBrowserExtender() { |
| 261 // This is a hack to BrowserExtender from a Tab. |
| 262 // TODO(oshima): Fix when the decision on compact location bar is made. |
| 263 // Potential candidates are: |
| 264 // * Use View ID with a cached reference to BrowserView. |
| 265 // * Pass the BrowserView reference to Tabs. |
| 266 // * Add GetBrowserView method to Delegate. |
| 267 TabStrip* tab_strip = static_cast<TabStrip*>(delegate_); |
| 268 return static_cast<BrowserView*>(tab_strip->GetParent())->browser_extender(); |
| 269 } |
| 270 |
| 239 void Tab::MakePathForTab(gfx::Path* path) const { | 271 void Tab::MakePathForTab(gfx::Path* path) const { |
| 240 DCHECK(path); | 272 DCHECK(path); |
| 241 | 273 |
| 242 SkScalar h = SkIntToScalar(height()); | 274 SkScalar h = SkIntToScalar(height()); |
| 243 SkScalar w = SkIntToScalar(width()); | 275 SkScalar w = SkIntToScalar(width()); |
| 244 | 276 |
| 245 path->moveTo(0, h); | 277 path->moveTo(0, h); |
| 246 | 278 |
| 247 // Left end cap. | 279 // Left end cap. |
| 248 path->lineTo(kTabBottomCurveWidth, h - kTabBottomCurveWidth); | 280 path->lineTo(kTabBottomCurveWidth, h - kTabBottomCurveWidth); |
| 249 path->lineTo(kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth); | 281 path->lineTo(kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth); |
| 250 path->lineTo(kTabCapWidth, 0); | 282 path->lineTo(kTabCapWidth, 0); |
| 251 | 283 |
| 252 // Connect to the right cap. | 284 // Connect to the right cap. |
| 253 path->lineTo(w - kTabCapWidth, 0); | 285 path->lineTo(w - kTabCapWidth, 0); |
| 254 | 286 |
| 255 // Right end cap. | 287 // Right end cap. |
| 256 path->lineTo(w - kTabCapWidth + kTabTopCurveWidth, kTabTopCurveWidth); | 288 path->lineTo(w - kTabCapWidth + kTabTopCurveWidth, kTabTopCurveWidth); |
| 257 path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth); | 289 path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth); |
| 258 path->lineTo(w, h); | 290 path->lineTo(w, h); |
| 259 | 291 |
| 260 // Close out the path. | 292 // Close out the path. |
| 261 path->lineTo(0, h); | 293 path->lineTo(0, h); |
| 262 path->close(); | 294 path->close(); |
| 263 } | 295 } |
| OLD | NEW |